Ready-to-use JavaScript examples
All banner networks use CGI scripts,
But we can do with the usual Java script.
This script will help you organize on your site
Or a banner page.
Первый фрагмент вы вставляете в любое место странички. Лучше в теге <HEAD>. <SCRIPT language=JavaScript>// <!-- Main function banners() { Дальше идёт перечисление ссылок и соответствующих им баннеров. Мы для примера берём 4 ссылки. this[1]="http://www.eurostar.com.ua/rus.htm"; Здесь вы пишете вашу ссылку. this[2]="http://www.eurostar.com.ua/img/banner468x60ru-1.gif"; Здесь указываете путь к графическому файлу this[3]="http://www.eurostar.com.ua/vac.htm"; this[4]="http://www.eurostar.com.ua/img/banner468x60ru-2.gif"; this[5]="http://www.eurostar.com.ua/promotion.htm"; this[6]="http://www.eurostar.com.ua/img/banner468x60ru-3.gif"; this[7]="http://www.eurostar.com.ua/promotion.htm"; this[8]="http://www.eurostar.com.ua/img/banner468x60ru-4.gif"; Количество таких ссылок может быть любым. Дальше идёт часть скрипта, которая как раз и отвечает за функцию обмена баннерами. Приведём его : if ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion.substring(0,1)) < 3)) { return(' '); } var j=(new Date()).getSeconds() % 4; document.write('<a href=' + this[2*j+1] + ' target=blank><img src=' + this[2*j+2] + ' border=0 width=468 height=60></a>'); return(' '); } // --></SCRIPT>Следует разобрать только одну переменную VAR J. Она должна соответствовать количеству показываемых баннеров. У нас это "4". Следующий фрагмент нужно разместить в том месте, где предполагается вывод на экран баннера. <center><SCRIPT language=JavaScript>// <!-- Main banners(); // --></SCRIPT>
EXAMPLE-2 Changing the picture
Change the picture when the document is loaded depending on the current
Time is carried out using the Date object.
Works in all browsers that support JavaScript.
<script language=JavaScript>function ban() { j=(new Date()).getSeconds()%2 this[0]="file1.gif" this[2]="file2.gif" вставьте свои картинки вместо file1.gif и file2.gif document.write("<img src=",this[2*j],">") return (" "); } </script><SCRIPT>document.write(ban()) </SCRIPT>
EXAMPLE-3 Voting
If there is no possibility of using CGI scripts,
And it is very important for you to receive responses from visitors
For specific questions, I recommend the following script.
Voting built using the mailto function.
<script LANGUAGE=JavaScript><!-- function SendMail(){ document.forms[0].action="mailto: name@company.com?body=Vote="+ document.forms[0].menu.options[document.forms[0]. menu.selectedIndex].value; } //--></script><form method=post name=form onsubmit=SendMail()><SELECT name=menu size=1> кол-во видимых полей 1-5 <option value=1>1 <option value=2>2 <option value=3>3 <option value=4>4 <option value=5>5 </select><input type=submit value="Отправить"></form>
EXAMPLE-4 Two frames
Java-script, which, by clicking on the link, opens
Page with two frames.
<a href=" javascript: loadFrames('http://www.eurostar.com.ua/', 'www.eurostar.com.ua/promotion.htm') "> Нажмите здесь. </a> <SCRIPT LANGUAGE=JavaScript><!-- Begin function loadFrames(page1, page2) { framecode = "<frameset rows='50%,50%'>" + "<frame src='" + page1 + "'>" + "<frame src='" + page2 + "'>" + "</frameset>"; page = window.open(""); page.document.open(); page.document.write(framecode); page.document.close(); } // End --></script>
EXAMPLE-5 The clock 02/17/2002 08:00:00
<script language=JavaScript>function fulltime() { var time=new Date(); document.clock.full.value=time.toLocaleString(); setTimeout('fulltime()',500) } </script><center><form name=clock><input type=text size=20 name=full></form><script language=JavaScript>fulltime(); </script>
EXAMPLE-6 Current date
Current date: Sun Feb 17 09:24:32 UTC + 0300 2002
<SCRIPT LANGUAGE=JavaScript> current_date = new Date(); document.write("<p><i>Текуща\я дата:</i> " + current_date + ".<p>"); </SCRIPT>
EXAMPLE-7 Date Date : 17.1.2002.
<SCRIPT LANGUAGE=JavaScript> current_date = new Date(); document.write("<i>Число:</i> " + current_date.getDate() + "." + current_date.getMonth() + "." + current_date.getYear() + "."); </SCRIPT>
EXAMPLE-8 Graphic clock and date
Additionally, you must have 14 .gif files, the total size of all
About 5 Kbt, to place in one folder with the document .html,
(Var text = " You can insert text here ")
Download .gif here
<SCRIPT LANGUAGE=JavaScript>document.write(setClock()) function setClock() { var text = "" var openImage = "<IMG SRC=\"" + getPath(location.href) + "dg" var closeImage = ".gif\" HEIGHT=21 WIDTH=16>" var now = new Date() var hour = now.getHours() var minute = now.getMinutes() now = null var ampm = "" if (hour >= 12) { hour -= 12 ampm = "pm" } else ampm = "am" hour = (hour == 0) ? 12 : hour if (minute < 10) minute = "0" + minute // do not parse this number! minute += "" hour += "" for (var i = 0; i < hour.length; ++i) { text += openImage + hour.charAt(i) + closeImage } text += openImage + "c.gif\" HEIGHT=21 WIDTH=9>" for (var i = 0; i < minute.length; ++i) { text += openImage + minute.charAt(i) + closeImage } text += openImage + ampm + closeImage return text}function getPath(url) { lastSlash = url.lastIndexOf("/") return url.substring(0, lastSlash + 1)} </SCRIPT><SCRIPT LANGUAGE=JavaScript>document.write(setDate()) function setDate() { var text = "" var openImage = "<IMG SRC=\"" + getPath(location.href) + "dg" var closeImage = ".gif\" HEIGHT=21 WIDTH=16>" var now = new Date() var date = now.getDate() var month = now.getMonth() var year = now.getYear() now = null month++ // 0 - 11 => 1 - 12 date += "" month += "" year += "" for (var i = 0; i < date.length; ++i) { text += openImage + date.charAt(i) + closeImage } text += openImage + "p.gif\" HEIGHT=21 WIDTH=9>" for (var i = 0; i < month.length; ++i) { text += openImage + month.charAt(i) + closeImage } text += openImage + "p.gif\" HEIGHT=21 WIDTH=9>" for (var i = 0; i < year.length; ++i) { text += openImage + year.charAt(i) + closeImage } return text}function getPath(url) { lastSlash = url.lastIndexOf("/") return url.substring(0, lastSlash + 1)} </SCRIPT>
EXAMPLE-9 Creeping line in the field
<script language=JavaScript>var line="Бегущая строка"; var speed=150; var i=0; function m_line() { if(i++<line.length) { document.cit.forum.value=line.substring(0,i); } else{ document.cit.forum.value=" "; i=0; } setTimeout('m_line()',speed); } </script><center><form name=cit><input type=text size=20 name=forum></form></center><script language=JavaScript>m_line(); </script>
EXAMPLE-10 Creeping line in the status line
<html><head><title>Бегущая строка</title><script language=javascript>function statusmessageobject(p,d) { this.msg = message this.out = " " this.pos = position this.delay = delay this.i = 0 this.reset = clearmessage } function clearmessage() { this.pos = position } var position = 100 var delay = 40 var message = "Бегущая строка" + " в строке статуса" var scroll = new statusmessageobject() function scroller() { for (scroll.i = 0; scroll.i < scroll.pos; scroll.i++) { scroll.out += " " } if (scroll.pos >= 0) scroll.out += scroll.msg else scroll.out = scroll.msg.substring(-scroll.pos,scroll.msg.length) window.status = scroll.out scroll.out = " " scroll.pos-- if (scroll.pos < -(scroll.msg.length)) { scroll.reset() } setTimeout ('scroller()',scroll.delay) } </script></head><body bgcolor=white onLoad=scroller()></body> </html>
EXAMPLE-11 WELCOME
The script allows you to welcome the visitor depending on the time of day.
Insert this code between tags ...
(Where 18 is the time after which the evening comes;
Good evening - the phrase of greeting, in case the time is evening;
12-the time after which the day comes;
Good afternoon - the phrase of greeting by day; Good morning - respectively in the morning.)
<SCRIPT LANGUAGE=JavaScript> <!-- Begin datetoday = new Date(); timenow=datetoday.getTime(); datetoday.setTime(timenow); thehour = datetoday.getHours(); if (thehour > 18) display = "Добрый вечер"; else if (thehour >12) display = "Добрый день"; else display = "Доброе утро"; document.write(display); // End --> </script>
EXAMPLE-12
Check if JavaScript is enabled in the browser
<script language=Javascript><!-- document.write('Yes! JavaScript!'); // --></script><noscript>Your browser can't do JavaScript. </noscript></script>
EXAMPLE-13 Very practical menu
<html><body text=white link=#ff5555 alink=#ff0000 vlink=#999999><style>.menu{ position: absolute; top:0; z-index: 2;} .submenu{ position: absolute; top: 22; z-index: 0; visibility: hide; visibility: hidden;} </style><script><!-- var old; var memold; var subold; if(document.layers) { window.captureEvents(Event.MOUSEDOWN); window.onmousedown=do_out; } else { document.onmouseup=do_out; } function show_layer(x) { if(document.layers) document.layers[x].visibility="show"; else document.all[x].style.visibility="visible"; } function hide_layer(x) { if(document.layers) document.layers[x].visibility="hide"; else document.all[x].style.visibility="hidden"; } function do_menu(x) { if(!old) old=memold; if(old!=x) { show_layer(x); old=x; } else old=""; } function do_check(x) { if(old && old!=x) { hide_layer(old); show_layer(x); old=x; } do_submenu(); } function do_out() { if(old) hide_layer(old); memold=old; old=""; do_submenu(); } function do_submenu(x) { if(subold) { hide_layer(subold); subold=""; } if(x) { show_layer(x); subold=x; } } // --></script><div id=m1 class=menu style="left: 5;"><table bgcolor=000000 cellspacing=0 cellpadding=2 border=1 width=115><tr><td><a href=javascript:do_menu('m1x') onmouseover="do_check('m1x')"><b>Системы</b></a></td></tr></table></code><div id=m1x class=submenu style="left: 5;"><table bgcolor=000000 cellspacing=0 cellpadding=2 border=1 width=115><tr><td><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http:&usg=ALkJrhjqQ5o8XoZ6TBRommQsVsVSARVnuA>Windows</a><br><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http:&usg=ALkJrhjqQ5o8XoZ6TBRommQsVsVSARVnuA>Mac</a><br><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http:&usg=ALkJrhjqQ5o8XoZ6TBRommQsVsVSARVnuA>Unix</a><br><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http:&usg=ALkJrhjqQ5o8XoZ6TBRommQsVsVSARVnuA>BeOS</a> </td></tr></table></div><div id=m2 class=menu style="left: 120;"><table bgcolor=000000 cellspacing=0 cellpadding=2 border=1 width=100><tr><td><a href=javascript:do_menu('m2x') onmouseover="do_check('m2x')"><b>Software</b></a></td></tr></table></div><div id=m2x class=submenu style="left: 120;"><table bgcolor=000000 cellspacing=0 cellpadding=2 border=1 width=100><tr><td><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http:&usg=ALkJrhjqQ5o8XoZ6TBRommQsVsVSARVnuA onmouseover="do_submenu('m21x')">Work</a> >><br><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http:&usg=ALkJrhjqQ5o8XoZ6TBRommQsVsVSARVnuA onmouseover=do_submenu()>Tools</a><br><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http:&usg=ALkJrhjqQ5o8XoZ6TBRommQsVsVSARVnuA onmouseover="do_submenu('m22x')">Spiele</a> >> </td></tr></table></div><div id=m21x class=submenu style="left: 180; top:24; z-index:1;"><table bgcolor=000000 cellspacing=0 cellpadding=2 border=1 width=100><tr><td><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http:&usg=ALkJrhjqQ5o8XoZ6TBRommQsVsVSARVnuA>Star Office</a><br><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http:&usg=ALkJrhjqQ5o8XoZ6TBRommQsVsVSARVnuA>Communicator</a><br><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http:&usg=ALkJrhjqQ5o8XoZ6TBRommQsVsVSARVnuA>Photoshop</a><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http:&usg=ALkJrhjqQ5o8XoZ6TBRommQsVsVSARVnuA>Freehand</a> </td></tr></table></div><div id=m22x class=submenu style="left: 180; top:58; z-index:1;"><table bgcolor=000000 cellspacing=0 cellpadding=2 border=1 width=100><tr><td><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http:&usg=ALkJrhjqQ5o8XoZ6TBRommQsVsVSARVnuA>Tomb Raider</a><br><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http:&usg=ALkJrhjqQ5o8XoZ6TBRommQsVsVSARVnuA>Quake</a><br><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http:&usg=ALkJrhjqQ5o8XoZ6TBRommQsVsVSARVnuA>Swing</a> </td></tr></table></div><div id=m3 class=menu style="left: 220;"><table bgcolor=000000 cellspacing=0 cellpadding=2 border=1 width=100><tr><td><a href=javascript:do_menu('m3x') onmouseover="do_check('m3x')"><b>Hardware</b></a></td></tr></table></div><div id=m3x class=submenu style="left: 220;"><table bgcolor=000000 cellspacing=0 cellpadding=2 border=1 width=100><tr><td><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http:&usg=ALkJrhjqQ5o8XoZ6TBRommQsVsVSARVnuA>PC</a><br><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http:&usg=ALkJrhjqQ5o8XoZ6TBRommQsVsVSARVnuA>Mac</a><br><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http:&usg=ALkJrhjqQ5o8XoZ6TBRommQsVsVSARVnuA>Amiga</a><br><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http:&usg=ALkJrhjqQ5o8XoZ6TBRommQsVsVSARVnuA>UNIX</a> </td></tr></table></div></body></html></div></div><br><br><hr style="color: red;"><br><br><P><font size=+2 color=Green><i>ПРИМЕР-14</i> <font size=+1>всплывающая подсказка</font></font><br>Следующий скрипт будет выдавать всплывающую подсказку при <br>наведении мыши на кнопку или просто на рисунок. <br><div><div class=spoiler_main2 onclick=show_hide_text(this)><u>» Нажмите, чтобы показать спойлер - нажмите опять, чтобы скрыть... «</u></div><div class=spoiler_main3><code><xmp> <html><head><meta content="text/html; charset=UTF-8" http-equiv=Content-Type><script language=JavaScript>if (parseInt(navigator.appVersion)>= 4) { if (navigator.appName == "Netscape") { layerStyleRef="layer."; layerRef="document.layers"; styleSwitch=""; } else { layerStyleRef="layer.style."; layerRef="document.all"; styleSwitch=".style"; } } function show(layerName) { if (parseInt(navigator.appVersion)>= 4) { eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"'); } } function cls(layerName){ if (parseInt(navigator.appVersion)>= 4) { eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"'); } } </script><style type=text/css>#text1 { HEIGHT: 80px; LEFT: 0px; POSITION: absolute; TOP: 50px; VISIBILITY: hidden; WIDTH: 250px; Z-INDEX: 10 } </style><meta content="Microsoft FrontPage 3.0" name=GENERATOR><title>Всплывающая подсказка</title></head><body bgColor=#FFFFFF text=#000000><div align=center id=text1 style="HEIGHT: 80px; LEFT: 10px; TOP: 15px; WIDTH: 250px"><table border=0 width=100% bgcolor=#000000 cellspacing=1 cellpadding=2><TBODY><tr><td align=middle bgcolor=#FFFFE1><p align=center><font face=Fixedsys color=#FF0000>Всплывающая подсказка</font></p><p align=left><font face="MS Sans Serif" size=1> А вот собственно и сама всплывающая подсказка...<br>Она удобна тем, что:<br>1. Она не исчезает в самый неподходящий момент (она исчезнет только после того, как вы уберёте курсор с ссылки);<br>2. Всплывающую подсказку можно добавлять не только к графической ссылке, но и к обычному тексту;<br>3. Здесь можно менять шрифты;<br>4. Можно менять цвета шрифтов;<br>5. Сюда можно вставлять рисунки и т.д.</font></td></tr></TBODY></table></code><p><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http://www.eurostar.com.ua/&usg=ALkJrhgD67CnIwWeD9mThOekdR7oTRJFcA onmouseout="cls('text1');" onmouseover="show('text1');"><img src=../img/banner88x31.jpg border=0 width=88 height=31></a></p></body></html></div></div><br><br><hr style="color: red;"><br><br><P><font size=+2 color=Green><i>ПРИМЕР-15</i> <font size=+1>Авто ссылка</font></font><br>Этот скрипт очень часто применяют для автоматического открытия <br>окна с ссылкой на какого-нибудь спонсора, <br>устанавливайте желаемые размеры окна<br><div><div class=spoiler_main2 onclick=show_hide_text(this)><u>» Нажмите, чтобы показать спойлер - нажмите опять, чтобы скрыть... «</u></div><div class=spoiler_main3><code><xmp> <SCRIPT LANGUAGE=JavaScript>window.open('ВАША ССЫЛКА',"PROBY",'height=300,width=550'); </SCRIPT>
EXAMPLE-16 Every day a new message
This script will give every day on your page a useful tip,
But maybe something else, in short, any of your messages.
<html><table border=0 width=100% bgcolor=#E8E8E8 cellspacing=0 cellpadding=0><tr><td width=100%><script><!-- var today_obj=new Date() var today_date=today_obj.getDate() var tips=new Array() //Можете вставить свой заголовок var tiptitle=' <b>Совет дня</b><br>' //Измените на свои советы tips[1]='Совет на 1 день месяца' tips[2]='Совет на 2 день месяца' tips[3]='Совет на 3 день месяца' tips[4]='Совет на 4 день месяца' tips[5]='Совет на 5 день месяца' tips[6]='Совет на 6 день месяца' tips[7]='Совет на 7 день месяца' tips[8]='Совет на 8 день месяца' tips[9]='Совет на 9 день месяца' tips[10]='Совет на 10 день месяца' tips[11]='Совет на 11 день месяца' tips[12]='Совет на 12 день месяца' tips[13]='Совет на 13 день месяца' tips[14]='Совет на 14 день месяца' tips[15]='Совет на 15 день месяца' tips[16]='Совет на 16 день месяца' tips[17]='Совет на 17 день месяца' tips[18]='Совет на 18 день месяца' tips[19]='Совет на 19 день месяца' tips[20]='Совет на 20 день месяца' tips[21]='Совет на 21 день месяца' tips[22]='Совет на 22 день месяца' tips[23]='Совет на 23 день месяца' tips[24]='Совет на 24 день месяца' tips[25]='Совет на 25 день месяца' tips[26]='Совет на 26 день месяца' tips[27]='Совет на 27 день месяца' tips[28]='Совет на 28 день месяца' tips[29]='Совет на 29 день месяца' tips[30]='Совет на 30 день месяца' tips[31]='Совет на 31 день месяца' document.write(tiptitle) document.write(tips[today_date]) //--></script></td></tr></table></HTML>
EXAMPLE-17 Falling snowflakes
This script creates on the page the effect of falling snow (leaves, etc.)
Change the picture in this line of the script:
Var snowflake = "1.gif"; ( Here you can download snowflakes, leaves )
<SCRIPT LANGUAGE=JavaScript1.2><!-- Begin var no = 35; // колличество снежинок var speed = 6; // скорость снежинок var snowflake = "1.gif"; var ns4up = (document.layers) ? 1 : 0; var ie4up = (document.all) ? 1 : 0; var dx, xp, yp; var am, stx, sty; var i, doc_width = 800, doc_height = 600; if (ns4up) { doc_width = self.innerWidth; doc_height = self.innerHeight; } else if (ie4up) { doc_width = document.body.clientWidth; doc_height = document.body.clientHeight; } dx = new Array(); xp = new Array(); yp = new Array(); am = new Array(); stx = new Array(); sty = new Array(); for (i = 0; i < no; ++ i) { dx[i] = 0; xp[i] = Math.random()*(doc_width-50); yp[i] = Math.random()*doc_height; am[i] = Math.random()*20; stx[i] = 0.02 + Math.random()/10; sty[i] = 0.7 + Math.random(); if (ns4up) { if (i == 0) { document.write("<layer name=\"dot"+ i +"\" left=\"15\" "); document.write("top=\"15\" visibility=\"show\"><img src=\""); document.write(snowflake + "\" border=\"0\"></layer>"); } else { document.write("<layer name=\"dot"+ i +"\" left=\"15\" "); document.write("top=\"15\" visibility=\"show\"><img src=\""); document.write(snowflake + "\" border=\"0\"></layer>"); } } else if (ie4up) { if (i == 0) { document.write("<div id=\"dot"+ i +"\" style=\"POSITION: "); document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: "); document.write("visible; TOP: 15px; LEFT: 15px;\"><img src=\""); document.write(snowflake + "\" border=\"0\">"); } else { document.write("<div id=\"dot"+ i +"\" style=\"POSITION: "); document.write("absolute; Z-INDEX: "+ i +"; VISIBILITY: "); document.write("visible; TOP: 15px; LEFT: 15px;\"><img src=\""); document.write(snowflake + "\" border=\"0\"></div>"); } } } function snowNS() { for (i = 0; i < no; ++ i) { yp[i] += sty[i]; if (yp[i] > doc_height-50) { xp[i] = Math.random()*(doc_width-am[i]-30); yp[i] = 0; stx[i] = 0.02 + Math.random()/10; sty[i] = 0.7 + Math.random(); doc_width = self.innerWidth; doc_height = self.innerHeight; } dx[i] += stx[i]; document.layers["dot"+i].top = yp[i]; document.layers["dot"+i].left = xp[i] + am[i]*Math.sin(dx[i]); } setTimeout("snowNS()", speed); } function snowIE() { for (i = 0; i < no; ++ i) { yp[i] += sty[i]; if (yp[i] > doc_height-50) { xp[i] = Math.random()*(doc_width-am[i]-30); yp[i] = 0; stx[i] = 0.02 + Math.random()/10; sty[i] = 0.7 + Math.random(); doc_width = document.body.clientWidth; doc_height = document.body.clientHeight; } dx[i] += stx[i]; document.all["dot"+i].style.pixelTop = yp[i]; document.all["dot"+i].style.pixelLeft = xp[i] + am[i]*Math.sin(dx[i]); } setTimeout("snowIE()", speed); } if (ns4up) { snowNS(); } else if (ie4up) { snowIE(); } // End --></script>
EXAMPLE-18 Add sound and video to the page
They can be started automatically when the page is loaded.
Below is the list of attributes that you can use
To achieve the desired goal
(They are all used in the & ltEMBED ...> </ EMBED> tag):
SRC = name.ext - name of audio, video clip.
ALIGN = CENTER - the location of the control panel (LEFT | CENTER | RIGHT).
WIDTH = X - where X is the width of the video clip in pixels.
HEIGHT = Y - where Y is the height of the video clip in pixels.
AUTOSTART = TRUE - allows or forbids the browser to launch a clip when the page is loaded (TRUE | FALSE).
REPEAT = TRUE - enables or disables repeating the audio / video clip (TRUE | FALSE).
PLAY_LOOP = Z - if you specified REPEAT = TRUE, specify here the number of repetitions instead of Z.
CONTROLS = SMALLCONSOLE - use this attribute if you want the control panel to be small.
HIDDEN = TRUE - and this attribute is necessary in order not to show the control panel (TRUE | FALSE).
Here are some examples of using audio / video clips
WAV файл со стандартным пультом управления: <EMBED SRC="файл.wav" WIDTH=145 HEIGHT=55></EMBED> MIDI файл со стандартным пультом управления: <EMBED SRC="файл.mid" WIDTH=145 HEIGHT=55></EMBED> AVI видео: <EMBED SRC="файл.avi" WIDTH=300 HEIGHT=200></EMBED>
EXAMPLE-19 Drop - down menu
If you want to use several drop-down menus on the page,
Each menu should have an individual name, it has a menu.
For example, if there are two menus then in the second menu write menu1
Instead of menu.
<form> <select name=menu> <option value=../notes.htm>Статьи - Все для Вебмастера <option selected value=java1-10.htm>Примеры JavaScript1-10 <option value=../applets.htm>Примеры апплетов <option value=../promotion.htm>Все для раскрутки сайта </select> <input type=button value=Ok onclick="top.location.href = this.form.menu.options[this.form.menu.selectedIndex].value"> </form>
EXAMPLE-20 Date of the document update
This script is designed to save your time.
Using it you do not have to change the date of updating the document
With each change. It is especially useful if you update
Very
<FONT SIZE=-1>Документ обновлен: <SCRIPT LANGUAGE=JavaScript><!-- document.writeln(document.lastModified) // --></SCRIPT></FONT>
EXAMPLE-21 Flashing links
This code is inserted between the & ltHEAD> ... </ HEAD> tags:
<script language=JavaScript><!-- function initArray() { for (var i = 0; i < initArray.arguments.length; i++) { this[i] = initArray.arguments[i]; } this.length = initArray.arguments.length; } // далее вы заполняете массив цветами, которые в последствии // и будут поочередно меняться у ссылки var colors = new initArray( "#008000", "green", "#C6C68C", "green", "blue", "purple", "black", "red"); pause_time = 0.5; // в секундах link = 0; // начиная с этого номера в массиве // (о котором уже говорилось выше) будут меняться цвета у ссылок vlink = 4; // тоже самое, только для просмотренных ссылок function linkDance() { link = (link+1)%colors.length; vlink = (vlink+1)%colors.length; document.linkColor = colors[link]; document.vlinkColor = colors[vlink]; setTimeout("linkDance();",pause_time*1000); } linkDance(); // --></script>
EXAMPLE-22 Underlining the reference when you hover the mouse over it
This code is inserted between the & ltHEAD> ... </ HEAD> tags:
<style type=text/css><!-- A:link {text-decoration: none;} A:visited {text-decoration: none;} A:hover {text-decoration: underline; } --></style>
EXAMPLE-23 Menu with backlight buttons, links
Substitute your .gif, links and use!
<HTML><HEAD> <title>меню с подсветкой кнопок, ссылок</title><script language=JavaScript1.2>function high(which2){ theobject=which2 highlighting=setInterval("highlightit(theobject)",50) } function low(which2){ clearInterval(highlighting) which2.filters.alpha.opacity=30 } function highlightit(cur2){ if (cur2.filters.alpha.opacity<100) cur2.filters.alpha.opacity+=5 else if (window.highlighting) clearInterval(highlighting) } </script></HEAD><BODY BGCOLOR=#ffffff TEXT=#000000 LINK=#0000FF VLINK=#7F007F ALINK=#FF0000><H2><center>Загарающееся меню.</H2><HR><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http://www.shram.kiev.ua/site/js.shtml&usg=ALkJrhgVUq4AcEcLWUjVYpg0SJaxyXNoeQ#nul><img src=name.gif border=0 style=filter:alpha(opacity=50) onMouseover=high(this) onMouseout=low(this)></a><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http://www.shram.kiev.ua/site/js.shtml&usg=ALkJrhgVUq4AcEcLWUjVYpg0SJaxyXNoeQ#nul><img src=name.gif border=0 style=filter:alpha(opacity=50) onMouseover=high(this) onMouseout=low(this)></a><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http://www.shram.kiev.ua/site/js.shtml&usg=ALkJrhgVUq4AcEcLWUjVYpg0SJaxyXNoeQ#nul><img src=name.gif border=0 style=filter:alpha(opacity=50) onMouseover=high(this) onMouseout=low(this)></a></BODY></HTML>
EXAMPLE-24 With the GO button
<Form><Select Name=mymenu> <Option Value=http://>Ваш текст - 1 <Option Value=http //">Ваш текст - 2 <Option Value=http //">Ваш текст - 3 <Option Value=http //">Ваш текст - 4 </Select> <Input Type=button Value=Go OnClick=top.location.href=this.form.mymenu.options[this.form.mymenu.selectedIndex].value></Form>
EXAMPLE-25 Menu without GO button
<Form><Input Type=hidden Name="select value"> <Select Name=sel Size=1 OnChange="top.location.href = this.options[this.selectedIndex].value;"> <Option selected value=#>Навигация по сайту</Option> <Option value=http://>Ваш текст - 1</Option> <Option value=http://>Ваш текст - 2</Option> <Option value=http://>Ваш текст - 3</Option> <Option value=http://>Ваш текст - 4</Option></Select></Form>
EXAMPLE-26 Menu Navigator, in the form
<TABLE border=2 bgcolor=black cellspacing=0 cellpadding=1><TD align=center><B><FONT FACE=arial FONT SIZE=+1 COLOR=white>НАВИГАТОР</FONT><br></B></TD></tr><tr> <script language=JavaScript> <!-- Hide this from older browsers function gotoPage (form) { if (form.way.selectedIndex == 0) parent.location="http://www.eurostar.com.ua"; if (form.way.selectedIndex == 1) parent.location="http://"; if (form.way.selectedIndex == 2) parent.location="http://"; if (form.way.selectedIndex == 3) parent.location="http://"; if (form.way.selectedIndex == 4) parent.location="http://"; if (form.way.selectedIndex == 5) parent.location="http://"; if (form.way.selectedIndex == 6) parent.location="http://"; if (form.way.selectedIndex == 7) parent.location="http://"; if (form.way.selectedIndex == 8) parent.location="http://"; if (form.way.selectedIndex == 9) parent.location="http://"; if (form.way.selectedIndex == 10) parent.location="http://"; if (form.way.selectedIndex == 11) parent.location="http://"; if (form.way.selectedIndex == 12) parent.location="http://www.eurostar.com.ua"; if (form.way.selectedIndex == 13) parent.location="http://www.eurostar.com.ua"; } document.write('<td valign="middle"><center><form name="WebNavigator">'); document.write('<select name="way" size="5" onChange="gotoPage(this.form)">'); document.write('<option>Евро Транс'); document.write('<option>2. Link'); document.write('<option>3. Link'); document.write('<option>4. Link'); document.write('<option>5. Link'); document.write('<option>6. Link'); document.write('<option>7. Link'); document.write('<option>8. Link'); document.write('<option>9. Link'); document.write('<option>10. Link'); document.write('<option>11. Link'); document.write('<option>12. Link'); document.write('<option>13. Link'); document.write('<option>14. Link'); document.write('</select>'); document.write('</form></td>'); // End hide --> </script></td></tr><tr><td align=center><b><font face=arial size=0 color=white>Выбирай и жми!</b></font></td></tr></table>
EXAMPLE-27 Menu with comments
<HTML><HEAD> <title>Меню с комментариями</title> <script><!-- var content=new Array() //change the array below to the text associated with your links Expand or contract the array, depending on how many links you have content[0]='<h3><font color="Green">Java Applets</font></h3>Примеры апплетов' content[1]='<h3><font color="Navy">Java Scripts</font></h3><br>Примеры JavaScript' content[2]='<h3><font color="Maroon">Архив Статей</font></h3><br>Архив статей - ВСЕ для ВЕБМАСТЕРА!' content[3]='<h3><font color="Olive">Промоушин</font></h3><br>Раскрутка сайта - самые эффективные методы' content[4]='<h3><font color="Purple">Справочники</font></h3><br>Ваш текст.</h3>' function regenerate(){ window.location.reload() } function regenerate2(){ if (document.layers) setTimeout("window.onresize=regenerate",450) } function changetext(whichcontent){ if (document.all) descriptions.innerHTML='<font face="Verdana"><small>'+whichcontent+'<font></small>' else if (document.layers){ document.d1.document.d2.document.write('<font face="Verdana"><small>'+whichcontent+'</small></font>') document.d1.document.d2.document.close() } } //--></script></HEAD><BODY BGCOLOR=#ffffff TEXT=#000000 LINK=#0000FF VLINK=#7F007F ALINK=#FF0000><center><H3><center>Меню с комментариями.</H3><HR><div id=scriptmenu style=line-height:20px><p><strong><font face=Verdana> <a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http://www.shram.kiev.ua/click%3Fhttp://www.eurostar.com.ua/applets.htm&usg=ALkJrhhtNGrQY9jyX23nGFnijmiTRV592Q onMouseover=changetext(content[0]) target=_blank><h6><font color=Green>Java Applets</font></a> <a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http://www.shram.kiev.ua/click%3Fhttp://www.eurostar.com.ua/java.htm&usg=ALkJrhiFiE_nBepqVB-ORXrPaYoZ76F_5w onMouseover=changetext(content[1]) target=_blank><font color=Navy>Java Scripts</font></a> <a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http://www.shram.kiev.ua/click%3Fhttp://www.eurostar.com.ua/notes.htm&usg=ALkJrhgOOz7lEfFLhaqjbx4Vin7QJ6fBXA onMouseover=changetext(content[2]) target=_blank><font color=Maroon>Архив статей</font></a> <a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http://www.shram.kiev.ua/promotion.htm&usg=ALkJrhgJdOOCah4JnvtzGn2mEbwAJIzzqQ onMouseover=changetext(content[3]) target=_blank><font color=Olive>Промоушин</font></a> <a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http://www.shram.kiev.ua/click%3Fhttp://www.eurostar.com.ua&usg=ALkJrhi7SmIDvQ2IGhZPvKQu7Rlpj7FXbQ onMouseover=changetext(content[4]) target=_blank><font color=Purple>Справочники</font></a></h6></font></strong></p>
EXAMPLE-28 Double menu
<SCRIPT LANGUAGE=JavaScript><!-- var maxLength = 10; website = new Array; website[0] = "Морской бизнес"; website[1] = "Все для Вебмастера"; website[2] = "Разное"; website[3] = "Трудоустройство"; var trueLength = website.length; var lst = website.length; url = new Array; url[0] = "http://"; url[1] = "http://"; url[2] = "http://"; url[3] = "http://"; url[4] = "http://"; ccselect = new Array; ccselect[0] = "Морской бизнес"; ccselect[1] = "Все для Вебмастера"; ccselect[2] = "Разное"; ccselect[3] = "Трудоустройство"; function changePage() { menuNum = document.ccDoubleList.ccBitsyG.selectedIndex; if (menuNum == null){alert("Please select a category from the menu.");return;} else { i = document.ccDoubleList.ccDoubleZ.selectedIndex; window.location.href = url[i]; } } function changeMenu() { website.length = 0; menuNum = document.ccDoubleList.ccBitsyG.selectedIndex; if (menuNum == null) return; if (menuNum == 0) { website = new Array; website[0] = new Option("Услуги нашего агентства"); website[1] = new Option("Оформление паспорта моряка"); website[2] = new Option("STCW документы"); website[3] = new Option("Морские ссылки(компании, порты, суда..."); website[4] = new Option("Открытые вакансии для моряков"); website[5] = new Option("Анкета для моряка"); website[6] = new Option("Cправочник морских сокращений"); website[7] = new Option("Наши реквизиты"); url = new Array; url[0] = "http://www.eurostar.com.ua/rus.htm"; url[1] = "http://www.eurostar.com.ua/seaid.htm"; url[2] = "http://www.eurostar.com.ua/stcw.htm"; url[3] = "http://www.eurostar.com.ua/mlink.htm"; url[4] = "http://www.eurotrans.com.ua/vac.htm"; url[5] = "http://www.eurostar.com.ua/form.doc"; url[6] = "http://www.eurostar.com.ua/az/az.htm"; url[7] = "http://www.eurostar.com.ua/contactru.htm"; } if (menuNum == 1) { website = new Array; website[0] = new Option("Статьи"); website[1] = new Option("Раскрутка сайта"); website[2] = new Option("Примеры аплетов"); website[3] = new Option("Примеры JavaScript"); website[4] = new Option("Полезные ссылки, проги"); website[5] = new Option("Обмен баннерами"); website[6] = new Option("Бесплатныe Web Site Hosting"); website[7] = new Option("Бесплатные e-mail"); url = new Array; url[0] = "http://www.eurostar.com.ua/notes.htm"; url[1] = "http://www.eurostar.com.ua/promotion.htm"; url[2] = "http://www.eurostar.com.ua/applets.htm"; url[3] = "http://www.eurostar.com.ua/java.htm"; url[4] = "http://www.eurostar.com.ua/ok.htm"; url[5] = "http://www.eurostar.com.ua/exch.htm"; url[6] = "http://www.eurostar.com.ua/freeweb.htm"; url[7] = "http://www.eurostar.com.ua/emailfree.htm"; } if (menuNum == 2) { website = new Array; website[0] = new Option("Мощный поисковик(42 в 1)"); website[1] = new Option("Обзор поисковиков "); website[2] = new Option("Обзор Каталогов"); website[3] = new Option("Доски бесплатных объявлений"); website[4] = new Option("Желтые страницы"); website[5] = new Option("Бесплатные звонки и факс"); website[6] = new Option("Бесплатные телефонные карточки"); website[7] = new Option("Виртуальный Херсон"); website[8] = new Option("Вся халява Инета здесь!"); url = new Array; url[0] = "http://www.eurostar.com.ua/multipoisk.htm"; url[1] = "http://www.eurostar.com.ua/search.htm"; url[2] = "http://www.eurostar.com.ua/catalog.htm"; url[3] = "http://www.eurostar.com.ua/bbs.htm"; url[4] = "http://www.eurostar.com.ua/yp.htm"; url[5] = "http://www.eurostar.com.ua/phfaxfree.htm"; url[6] = "http://www.eurostar.com.ua/phcardfree.htm"; url[7] = "http://www.eurostarstar.com.ua/kherson.htm"; url[8] = "http://top-halyava.ru/index.php?id=823"; } if (menuNum == 3) { website = new Array; website[0] = new Option("a"); website[1] = new Option("b"); website[2] = new Option("c"); website[3] = new Option("d"); website[4] = new Option("e"); url = new Array; url[0] = "http://"; url[1] = "http://"; url[2] = "http://"; url[3] = "http://"; url[4] = "http://"; } tot = website.length; for (i = lst; i > 0; i--) { document.ccDoubleList.ccDoubleZ.options[i] = null; } for (i = 0; i < tot; i++) { document.ccDoubleList.ccDoubleZ.options[i] = website[i]; } document.ccDoubleList.ccDoubleZ.options[0].selected = true; lst = website.length; } // --></SCRIPT><SCRIPT LANGUAGE=JavaScript><!-- with (document) { writeln('<CENTER>'); writeln('<TABLE BORDER=3 BGCOLOR=#ffffff CELLPADDING=3 CELLSPACING=0>'); writeln('<TR><TD COLSPAN=3><FORM NAME="ccDoubleList">'); writeln('<CENTER><FONT SIZE=4 COLOR=#808080 FACE=ARIAL>'); writeln('<font color="Green">Двойное меню</font></FONT></CENTER>'); writeln('</TD></TR><TR><TD ALIGN=LEFT>'); writeln('<FONT SIZE=3 COLOR=#808080 FACE=ARIAL><B><font color="Navy"><center>Меню</font></B></FONT><br>'); writeln('<SELECT NAME="ccBitsyG" onChange="changeMenu(this.form)">'); tot = ccselect.length; for (i = 0; i < tot; i++) writeln("<OPTION>" +ccselect[i]); writeln("</SELECT>"); writeln('</TD><TD>'); writeln('<FONT SIZE=3 COLOR=#808080 FACE=ARIAL><B><font color="Blue"><center>Подменю</font></B></FONT><br>'); writeln('<SELECT NAME="ccDoubleZ">'); for (i = 0; i < maxLength; i++) writeln("<OPTION>" +website[i]); writeln("</SELECT>"); for (i = maxLength; i > trueLength; i--) { ccDoubleList.ccDoubleZ.options[i] = null; } writeln('</TD><TD VALIGN=center><A HREF = "javascript:changePage();">'); writeln('<font size="+3" color="Green"><b>GO</b></font></a>'); writeln('</TD></TR>'); changeMenu(); writeln('</FORM>'); writeln('</TABLE><P><br><P>'); writeln('</CENTER>'); } // --></SCRIPT></center>
EXAMPLE-29 Menu with submenu
<script language=JavaScript1.2><!-- var head="display:''" function doit(header){ var head=header.style if (head.display=="none") head.display="" else head.display="none" } //--></script><h3 style=cursor:hand onClick=doit(document.all[this.sourceIndex+1])>Меню 1</h3><span style=display:none style=&{head};><A href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http://www.shram.kiev.ua/site/js.shtml&usg=ALkJrhgVUq4AcEcLWUjVYpg0SJaxyXNoeQ#nul>Links 1</A><br><A href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http://www.shram.kiev.ua/site/js.shtml&usg=ALkJrhgVUq4AcEcLWUjVYpg0SJaxyXNoeQ#nul>Links 2</A><br><A href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http://www.shram.kiev.ua/site/js.shtml&usg=ALkJrhgVUq4AcEcLWUjVYpg0SJaxyXNoeQ#nul>Links 3</A><br></span><h3 style=cursor:hand onClick=doit(document.all[this.sourceIndex+1])>Меню 2</h3><span style=display:none style=&{head};><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http://www.shram.kiev.ua/site/js.shtml&usg=ALkJrhgVUq4AcEcLWUjVYpg0SJaxyXNoeQ#nul><img src=name.gif border=0></A><br><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http://www.shram.kiev.ua/site/js.shtml&usg=ALkJrhgVUq4AcEcLWUjVYpg0SJaxyXNoeQ#nul><img src=name.gif border=0></A><br><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http://www.shram.kiev.ua/site/js.shtml&usg=ALkJrhgVUq4AcEcLWUjVYpg0SJaxyXNoeQ#nul><img src=name.gif border=0></A><br></span>
EXAMPLE-30 When clicked, the menu is advanced from the top.
<script language=JavaScript>var eypos=-200, ejump=-4; var typos=-260, tjump=-4; var delay=2; function do_menue() { if(typos>-260) { tjump=-4; if(typos>=130) head_fahren(); } ejump=-ejump; if(eypos<=-200 || eypos>=20) menue_fahren(); } function menue_fahren() { if(document.layers) document.menue.top=eypos; else document.all.menue.style.top=eypos; eypos+=ejump; if(eypos>-200 && eypos<20) setTimeout("menue_fahren()", delay); } function do_head() { if(eypos>-200) { ejump=-4; if(eypos>=20) menue_fahren(); } tjump=-tjump; if(typos<=-260 || typos>=130) head_fahren(); } function head_fahren() { if(document.layers) document.head.top=typos; else document.all.head.style.top=typos; typos+=tjump; if(typos>-260 && typos<130) setTimeout("head_fahren()", delay); } </script></HEAD><BODY BGCOLOR=#DDDDDD TEXT=#000000 LINK=#0000FF VLINK=#7F007F ALINK=#FF0000><div style="position:absolute; z-index:2; left:300;"><TABLE BORDER=0><TR><TD align=center>Навигация по сайту.</TD></TR><TR><BIG><TD align=center><a href=javascript:do_menue()>Нажми здесь!</a></BIG></TD></TR></TABLE>
EXAMPLE-31 Changing text
The width and height of the area with the text is specified by the parameters:
Var fwidth = 160 var fheight = 150
The delay in the appearance of text is specified by the parameter: faderdelay = 2000
<script language=JavaScript1.2> var delay=3500 var fcontent=new Array() begintag='<font face="Arial" size=2>' fcontent[0]="Здесь помещается текст, который вы хотите показывать " fcontent[1]="Этот текст будет периодически меняться..." fcontent[2]="Таких строк может быть сколько угодно." fcontent[3]="Не забывайте заходить на сайт WWW.EUROSTAR.COM.UA/JAVA.HTM" closetag='</font>' var fwidth=200 var fheight=150 var ie4=document.all&&!document.getElementById var ns4=document.layers var DOM2=document.getElementById var faderdelay=0 var index=0 if (DOM2) faderdelay=2000 function changecontent(){ if (index>=fcontent.length) index=0 if (DOM2){ document.getElementById("fscroller").style.color="rgb(255,255,255)" document.getElementById("fscroller").innerHTML=begintag+fcontent[index]+closetag colorfade() } else if (ie4) document.all.fscroller.innerHTML=begintag+fcontent[index]+closetag else if (ns4){ document.fscrollerns.document.fscrollerns_sub.document.write(begintag+fcontent[index]+closetag) document.fscrollerns.document.fscrollerns_sub.document.close() } index++ setTimeout("changecontent()",delay+faderdelay) } frame=20; hex=255 function colorfade() { if(frame>0) { hex-=12; document.getElementById("fscroller").style.color="rgb("+hex+","+hex+","+hex+")"; frame--; setTimeout("colorfade()",20); } else{ document.getElementById("fscroller").style.color="rgb(0,0,0)"; frame=20; hex=255 } } if (ie4||DOM2) document.write('<div id="fscroller" style="border:0px solid black;width:' +fwidth+';height:'+fheight+';padding:2px">
EXAMPLE-32 Menu with the SELECT button
<Form Name=take><Select Name=take2 Size=7> <Option Selected Value=../java.htm>JavaScript</Option> <Option Value=../applets.html>Applets</Option> <Option Value=../notes.htm>Cтатьи-Все для Вебмастера</Option> <Option Value=../promotion.htm>Раскрутка сайта</Option> <Option Value=http://www.eurostar.com.ua>Главная</Option> <Option Value=http://>Ваш текст - 1</Option> <Option Value=http://>Ваш текст - 2</Option> <Option Value=http://>Ваш текст - 3</Option> <Option Value=http://>Ваш текст - 4</Option></Select><Script> function taking() {location=document.take.take2.options[document.take.take2.selectedIndex].value} </Script><br><Input Type=button Value="Выбрать" Name=B1 OnClick=taking()></Form>
EXAMPLE-33 The menu opens when you hover over the inscription
<HTML><HEAD><STYLE type=text/css>A:link { COLOR: #ffffff; FONT: 9pt Arial; TEXT-DECORATION: none} A:visited { COLOR: #ffffff; FONT: 9pt Arial; TEXT-DECORATION: none} A:hover { COLOR: #0000ff; FONT: 9pt Arial; TEXT-DECORATION: none} </STYLE></HEAD><BODY><TABLE border=0 height=100 onmouseout="bgColor=''" onmouseover="bgColor='gray'" width=200><TBODY><TR><TD bgColor=navy><FONT color=white><B>Навигация по сайту</B></FONT></TD><TR><TD onmouseout="bgColor=''" onmouseover="bgColor='76e000'"><A href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http://www.shram.kiev.ua/click%3Fhttp://www.eurostar.com.ua/applets.htm&usg=ALkJrhhtNGrQY9jyX23nGFnijmiTRV592Q><b>Java апплеты</b></A></TD><TR><TD onmouseout="bgColor=''" onmouseover="bgColor='76e000'"><A href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http://www.shram.kiev.ua/click%3Fhttp://www.eurostar.com.ua/java.htm&usg=ALkJrhiFiE_nBepqVB-ORXrPaYoZ76F_5w><b>Java Scripts</b></A></TD><TR><TD onmouseout="bgColor=''" onmouseover="bgColor='76e000'"><A href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http://www.shram.kiev.ua/click%3Fhttp://www.eurostar.com.ua/notes.htm&usg=ALkJrhgOOz7lEfFLhaqjbx4Vin7QJ6fBXA><b>Статьи</b>-<font size=-2>Все для Вебмастера</font></A> </TD></TR></TBODY></TABLE></BODY></HTML>
EXAMPLE-34 Movable menu
Works only in IE. Very convenient and versatile menu. It can be placed anywhere on the site, and insert into it anything you like - text, graphics and scripts. The peculiarity of the menu is that it always remains on the screen when scrolling and it can be moved with the mouse across the entire screen.
<HTML><HEAD><style TYPE=text/css>#superbest { position: absolute; left: 15; top: 150; width: 125; visibility: visible; z-index: 10; </style></HEAD><BODY><div ID=superbest style="width: 206; height: 194"><dd><table BORDER=1 CELLPADDING=0 CELLSPACING=0 width=100%><tr><td bgcolor=green size=-2><font size=-2>меню</font><td bgcolor=white><font face=arial,helvetica size=-1><font color=Green><b>Перемещаемое</b></font><br><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http://www.shram.kiev.ua/click%3Fhttp://www.eurostar.com.ua/java.htm&usg=ALkJrhiFiE_nBepqVB-ORXrPaYoZ76F_5w target=_blank>Коллекция скриптов<br></a><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http://www.shram.kiev.ua/click%3Fhttp://www.eurostar.com.ua/applets.htm&usg=ALkJrhhtNGrQY9jyX23nGFnijmiTRV592Q target=_blank>Коллекция апплетов<br></a><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http://www.shram.kiev.ua/click%3Fhttp://www.eurostar.com.ua/notes.htm&usg=ALkJrhgOOz7lEfFLhaqjbx4Vin7QJ6fBXA target=_blank>Архив статей-ВСЕ для Вебмастера<br></a><a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http://www.shram.kiev.ua/click%3Fhttp://www.eurostar.com.ua/promotion.htm&usg=ALkJrhidaHNi74OE0GR7yjtdZZ44uxr1Xw target=_blank> Раскрутка сайта<br></a> <a href=http://translate.googleusercontent.com/translate_c?depth=1&hl=ru&prev=hp&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=http://www.shram.kiev.ua/click%3Fhttp://www.eurostar.com.ua/exch.htm&usg=ALkJrhjFKs2mkOAkw-nYAjsoJGObR3SCIA target=_blank>Обмен баннерами</a></font><br> <script LANGUAGE=JavaScript><!-- self.onError=null; currentX = currentY = 0; whichIt = null; lastScrollX = 0; lastScrollY = 0; NS = (document.layers) ? 1 : 0; IE = (document.all) ? 1: 0; <!-- STALKER CODE -->function heartBeat() { if(IE) { diffY = document.body.scrollTop; diffX = document.body.scrollLeft; } if(NS) { diffY = self.pageYOffset; diffX = self.pageXOffset; } if(diffY != lastScrollY) { percent = .1 * (diffY - lastScrollY); if(percent > 0) percent = Math.ceil(percent); else percent = Math.floor(percent); if(IE) document.all.superbest.style.pixelTop += percent; if(NS) document.superbest.top += percent; lastScrollY = lastScrollY + percent; } if(diffX != lastScrollX) { percent = .1 * (diffX - lastScrollX); if(percent > 0) percent = Math.ceil(percent); else percent = Math.floor(percent); if(IE) document.all.superbest.style.pixelLeft += percent; if(NS) document.superbest.left += percent; lastScrollX = lastScrollX + percent; } } <!-- /STALKER CODE --><!-- DRAG DROP CODE -->function checkFocus(x,y) { stalkerx = document.superbest.pageX; stalkery = document.superbest.pageY; stalkerwidth = document.superbest.clip.width; stalkerheight = document.superbest.clip.height; if( (x > stalkerx && x < (stalkerx+stalkerwidth)) && (y > stalkery && y < (stalkery+stalkerheight))) return true; else return false; } function grabIt(e) { if(IE) { whichIt = event.srcElement; while (whichIt.id.indexOf("superbest") == -1) { whichIt = whichIt.parentElement; if (whichIt == null) { return true; } } whichIt.style.pixelLeft = whichIt.offsetLeft; whichIt.style.pixelTop = whichIt.offsetTop; currentX = (event.clientX + document.body.scrollLeft); currentY = (event.clientY + document.body.scrollTop); } else { window.captureEvents(Event.MOUSEMOVE); if(checkFocus (e.pageX,e.pageY)) { whichIt = document.superbest; StalkerTouchedX = e.pageX-document.superbest.pageX; StalkerTouchedY = e.pageY-document.superbest.pageY; } } return true; } function moveIt(e) { if (whichIt == null) { return false; } if(IE) { newX = (event.clientX + document.body.scrollLeft); newY = (event.clientY + document.body.scrollTop); distanceX = (newX - currentX); distanceY = (newY - currentY); currentX = newX; currentY = newY; whichIt.style.pixelLeft += distanceX; whichIt.style.pixelTop += distanceY; if(whichIt.style.pixelTop < document.body.scrollTop) whichIt.style.pixelTop = document.body.scrollTop; if(whichIt.style.pixelLeft < document.body.scrollLeft) whichIt.style.pixelLeft = document.body.scrollLeft; if(whichIt.style.pixelLeft > document.body.offsetWidth - document.body.scrollLeft - whichIt.style.pixelWidth - 20) whichIt.style.pixelLeft = document.body.offsetWidth - whichIt.style.pixelWidth - 20; if(whichIt.style.pixelTop > document.body.offsetHeight + document.body.scrollTop - whichIt.style.pixelHeight - 5) whichIt.style.pixelTop = document.body.offsetHeight + document.body.scrollTop - whichIt.style.pixelHeight - 5; event.returnValue = false; } else { whichIt.moveTo(e.pageX-StalkerTouchedX,e.pageY-StalkerTouchedY); if(whichIt.left < 0+self.pageXOffset) whichIt.left = 0+self.pageXOffset; if(whichIt.top < 0+self.pageYOffset) whichIt.top = 0+self.pageYOffset; if( (whichIt.left + whichIt.clip.width) >= (window.innerWidth+self.pageXOffset-17)) whichIt.left = ((window.innerWidth+self.pageXOffset)-whichIt.clip.width)-17; if( (whichIt.top + whichIt.clip.height) >= (window.innerHeight+self.pageYOffset-17)) whichIt.top = ((window.innerHeight+self.pageYOffset)-whichIt.clip.height)-17; return false; } return false; } function dropIt() { whichIt = null; if(NS) window.releaseEvents (Event.MOUSEMOVE); return true; } <!-- DRAG DROP CODE -->if(NS) { window.captureEvents(Event.MOUSEUP|Event.MOUSEDOWN); window.onmousedown = grabIt; window.onmousemove = moveIt; window.onmouseup = dropIt; } if(IE) { document.onmousedown = grabIt; document.onmousemove = moveIt; document.onmouseup = dropIt; } if(NS || IE) action = window.setInterval("heartBeat()",1); // --></script></td> </tr> </table></dd>
EXAMPLE-35 Dynamic menu
<HTML><HEAD><script LANGUAGE=JavaScript>function makeArray(q){ for(i=1 ; i < q ; i++){this[i]=0}} w=1; howmanysites=5; // Цифра 5 указывает сколько ссылок в скрипте Sites = new makeArray(howmanysites); Sites[1] = "http://www.eurostar.com.ua/notes.htm|Архив статей - ВСЕ для Вебмастера!"; //впишите адрес URL перед символом | а далее название ссылки. Sites[2] = "http://www.eurostar.com.ua/java.htm|Примеры JavaScript"; Sites[3] = "http://www.eurostar.com.ua/applets.htm|Примеры апплетов"; Sites[4] = "http://www.eurostar.com.ua/promotion.htm|Раскрутка сайта"; Sites[5] = "http://www.eurostar.com.ua/az/az.htm|Cправочник морской терминологии"; function showSites() { if (w > howmanysites) { w=1; }; var string=Sites[w] + ""; var split=string.indexOf("|"); var url=string.substring(0,split); var word=string.substring(split + 1,string.length); document.form.url.value=url; document.form.word.value=word; w+=1; window.setTimeout('showSites()',3000); // Время переключения в милисекундах, 3000=3 секунд } function visitSite() { window.location=document.form.url.value; } // End --></script></head><body><center><form name=form><input type=hidden name=url value><table><tr><td align=center><input type=text name=word value onFocus=visitSite() size=40> </td></tr></table></form><script>showSites(); </script></center></BODY></HTML>
EXAMPLE-36 Menu on a colored background with GO button!
<form method=POST action=--WEBBOT-SELF-- name=test><script>function warp(){ window.location=document.test.test2.options[document.test.test2.selectedIndex].value } </script><center><select name=test2 size=1 style="background-color: rgb(25,238,255); font-weight: bold"> <option selected value=http://www.eurostar.com.ua/notes.htm> Cтатьи-ВСЕ для ВЕБМАСТЕРА!</option> <option value=http://www.eurostar.com.ua/java.htm>Примеры JavaScript</option> <option value=http://www.eurostar.com.ua/applets.htm>Примеры апплетов</option> <option value=http://www.eurostar.com.ua/promotion.htm>Раскрутка сайта</option> <option value=http://www.eurostar.com.ua/az/az.htm>Морская терминология</option> <option value=http://www.eurostar.com.ua/vac.htm>Открытые вакансии для моряков</option> </select> <a href=javascript:warp() style=text-decoration:none;color:navy;><font face=Arial><font size=+2>Go!</font></font></a></p> </form></center>
EXAMPLE-37 The menu appears after clicking on the picture
(Button, banner, link)
<html><head><SCRIPT LANGUAGE=JavaScript> var visibleVar="null"; function init(){ if (navigator.appName == "Netscape") { layerStyleRef="layer."; layerRef="document.layers"; styleSwitch=""; visibleVar="show"; }else{ layerStyleRef="layer.style."; layerRef="document.all"; styleSwitch=".style"; visibleVar="visible"; } } function showHideLayerSwitch(layerName){ if (eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility == visibleVar')){ hideLayer(layerName); }else{ showLayer(layerName); } } function showLayer(layerName){ eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="visible"'); } function hideLayer(layerName){ eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility="hidden"'); } function showLayer1(layerName){ if (eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility == visibleVar')){ showLayer(layerName); } } function hideLayer1(layerName){ if (eval(layerRef+'["'+layerName+'"]'+styleSwitch+'.visibility == visibleVar')){ hideLayer(layerName); } } </SCRIPT><STYLE TYPE=text/css>#pulldownButton {position: absolute; z-index: 59800; left: 300px; top: 50px;} #pulldownMenu {position: absolute; z-index: 59900; visibility: hidden; left: 100px; top: 116px;} </STYLE></head><body bgcolor=#000000 text=#ffffff link=#ff5555 alink=#ff0000 vlink=#999999 onload=init()> <div id=pulldownButton> <a href=javascript:showHideLayerSwitch('pulldownMenu');> <IMG SRC=arrow-left.gif BORDER=0 alt="Жми, здесь ME Н Ю"></a>
JavaScript Examples | 2-1 | 3-1 |
Examples of Applets | 2-2 | 3-2 |
Articles Archive | 2-3 | 3-3 |
Main Internet terms | 2-4 | 3-4 |
Website promotion | 2-5 | 3-5 |
EXAMPLE-38 Drop - down menu without a button - navigate the site
<Form><Input Type=hidden Name="select value"> <Select Name=sel Size=1 OnChange="top.location.href = this.options[this.selectedIndex].value;"> <Option selected value=#>Навигация по сайту</Option> <Option value=http://>Ваш текст - 1</Option> <Option value=http://>Ваш текст - 2</Option> <Option value=http://>Ваш текст - 3</Option> <Option value=http://>Ваш текст - 4</Option></Select></Form>
EXAMPLE-39 Drop - down menu without a button - navigate the site
On a colored background
<form> <select name=sel size=1 onchange="top.location.href = this.options[this.selectedIndex].value;" style="background-color: rgb(0,0,0); color: rgb(55,255,0); font-weight: bolder"> <option value=#nul>Навигация по сайту:</option> <option value=#nul>Ваша ссылка-1</option> <option value=#nul>Ваша ссылка-2</option> <option value=#nul>Ваша ссылка-3</option> </select> </p> </center>
EXAMPLE-40 Date, time UTC in the status line
<html><HEAD> <SCRIPT LANGUAGE=JavaScript><!-- function show_date_time() { var now=new Date(); window.status=now; window.setTimeout("show_date_time();",1000); } // --></SCRIPT> </HEAD><BODY BGCOLOR=#FFFFFF TEXT=#000000 ></BODY></html>
EXAMPLE-41 Scrolling text
<HTML><HEAD><title>Text Block Scrolling</title><SCRIPT LANGUAGE=JavaScript>var line_beak = "\n" var screen = "" // 1234567890123456789012345678901234567890 screen += "Будем прокручивать " screen += "Данный фрагмент текста " screen += "В поле типа " screen += "TEXTAREA " screen += "формы term " for(i=0;i<6;i++) screen += " " var i=0 var j=40 flag = 0 function scroll() { if( flag== 0 ) { display_str = "" for(k=0;k<11;k++) { display_str += screen.substring(i,j) i +=40;j = i + 40 if(i>400) i = 0 } window.document.term.work_field.value = display_str i += 40 ; if(i>400) i =0 } id = setTimeout("scroll()",1000) return true } function change_button() { if(flag==0) { flag = 1 return true } if(flag == 1) { flag = 0 return false } } </SCRIPT></HEAD><BODY onLoad=scroll()><CENTER><H1>Text Block Scrolling.</H1><HR><FORM NAME=term><TEXTAREA NAME=work_field COLS=40 ROWS=10 WRAP=ON>< /TEXTAREA><P><INPUT NAME=alarm VALUE="Start/Stop" TYPE=button onClick="change_button()"></FORM></CENTER><HR></BODY></HTML>
EXAMPLE-42 Calendar 2000 - 2004
<!-- Вставьте эту часть кода между тегами <HEAD></HEAD> вашего документа --><HEAD><SCRIPT LANGUAGE="JavaScript"><!-- Oригинал: Nick Korosi (nfk2000@hotmail.com) --><!-- Begin var dDate = new Date(); var dCurMonth = dDate.getMonth(); var dCurDayOfMonth = dDate.getDate(); var dCurYear = dDate.getFullYear(); var objPrevElement = new Object(); function fToggleColor(myElement) { var toggleColor = "#ff0000"; if (myElement.id == "calDateText") { if (myElement.color == toggleColor) { myElement.color = ""; } else { myElement.color = toggleColor; } } else if (myElement.id == "calCell") { for (var i in myElement.children) { if (myElement.children[i].id == "calDateText") { if (myElement.children[i].color == toggleColor) { myElement.children[i].color = ""; } else { myElement.children[i].color = toggleColor; } } } } } function fSetSelectedDay(myElement){ if (myElement.id == "calCell") { if (!isNaN(parseInt(myElement.children["calDateText"].innerText))) { myElement.bgColor = "#c0c0c0"; objPrevElement.bgColor = ""; document.all.calSelectedDate.value = parseInt(myElement.children["calDateText"].innerText); objPrevElement = myElement; } } } function fGetDaysInMonth(iMonth, iYear) { var dPrevDate = new Date(iYear, iMonth, 0); return dPrevDate.getDate(); } function fBuildCal(iYear, iMonth, iDayStyle) { var aMonth = new Array(); aMonth[0] = new Array(7); aMonth[1] = new Array(7); aMonth[2] = new Array(7); aMonth[3] = new Array(7); aMonth[4] = new Array(7); aMonth[5] = new Array(7); aMonth[6] = new Array(7); var dCalDate = new Date(iYear, iMonth-1, 1); var iDayOfFirst = dCalDate.getDay(); var iDaysInMonth = fGetDaysInMonth(iMonth, iYear); var iVarDate = 1; var i, d, w; if (iDayStyle == 2) { aMonth[0][0] = "Воскресенье"; aMonth[0][1] = "Понедельник"; aMonth[0][2] = "Вторник"; aMonth[0][3] = "Среда"; aMonth[0][4] = "Четверг"; aMonth[0][5] = "Пятница"; aMonth[0][6] = "Суббота"; } else if (iDayStyle == 1) { aMonth[0][0] = "Вск"; aMonth[0][1] = "Пон"; aMonth[0][2] = "Вт"; aMonth[0][3] = "Ср"; aMonth[0][4] = "Чт"; aMonth[0][5] = "Пт"; aMonth[0][6] = "Сб"; } else { aMonth[0][0] = "Вс"; aMonth[0][1] = "Пн"; aMonth[0][2] = "Вт"; aMonth[0][3] = "Ср"; aMonth[0][4] = "Чт"; aMonth[0][5] = "Пт"; aMonth[0][6] = "Сб"; } for (d = iDayOfFirst; d < 7; d++) { aMonth[1][d] = iVarDate; iVarDate++; } for (w = 2; w < 7; w++) { for (d = 0; d < 7; d++) { if (iVarDate <= iDaysInMonth) { aMonth[w][d] = iVarDate; iVarDate++; } } } return aMonth; } function fDrawCal(iYear, iMonth, iCellWidth, iCellHeight, sDateTextSize, sDateTextWeight, iDayStyle) { var myMonth; myMonth = fBuildCal(iYear, iMonth, iDayStyle); document.write("<table border='1'>") document.write("<tr>"); document.write("<td align='center' style='FONT-FAMILY:Arial;FONT-SIZE:12px;FONT-WEIGHT: bold'>" + myMonth[0][0] + "</td>"); document.write("<td align='center' style='FONT-FAMILY:Arial;FONT-SIZE:12px;FONT-WEIGHT: bold'>" + myMonth[0][1] + "</td>"); document.write("<td align='center' style='FONT-FAMILY:Arial;FONT-SIZE:12px;FONT-WEIGHT: bold'>" + myMonth[0][2] + "</td>"); document.write("<td align='center' style='FONT-FAMILY:Arial;FONT-SIZE:12px;FONT-WEIGHT: bold'>" + myMonth[0][3] + "</td>"); document.write("<td align='center' style='FONT-FAMILY:Arial;FONT-SIZE:12px;FONT-WEIGHT: bold'>" + myMonth[0][4] + "</td>"); document.write("<td align='center' style='FONT-FAMILY:Arial;FONT-SIZE:12px;FONT-WEIGHT: bold'>" + myMonth[0][5] + "</td>"); document.write("<td align='center' style='FONT-FAMILY:Arial;FONT-SIZE:12px;FONT-WEIGHT: bold'>" + myMonth[0][6] + "</td>"); document.write("</tr>"); for (w = 1; w < 7; w++) { document.write("<tr>") for (d = 0; d < 7; d++) { document.write("<td align='left' valign='top' width='" + iCellWidth + "' height='" + iCellHeight + "' id=calCell style='CURSOR:Hand' onMouseOver='fToggleColor(this)' onMouseOut='fToggleColor(this)' onclick=fSetSelectedDay(this)>"); if (!isNaN(myMonth[w][d])) { document.write("<font id=calDateText onMouseOver='fToggleColor(this)' style='CURSOR:Hand;FONT-FAMILY:Arial;FONT-SIZE:" + sDateTextSize + ";FONT-WEIGHT:" + sDateTextWeight + "' onMouseOut='fToggleColor(this)' onclick=fSetSelectedDay(this)>" + myMonth[w][d] + "</font>"); } else { document.write("<font id=calDateText onMouseOver='fToggleColor(this)' style='CURSOR:Hand;FONT-FAMILY:Arial;FONT-SIZE:" + sDateTextSize + ";FONT-WEIGHT:" + sDateTextWeight + "' onMouseOut='fToggleColor(this)' onclick=fSetSelectedDay(this)> </font>"); } document.write("</td>") } document.write("</tr>"); } document.write("</table>") } function fUpdateCal(iYear, iMonth) { myMonth = fBuildCal(iYear, iMonth); objPrevElement.bgColor = ""; document.all.calSelectedDate.value = ""; for (w = 1; w < 7; w++) { for (d = 0; d < 7; d++) { if (!isNaN(myMonth[w][d])) { calDateText[((7*w)+d)-7].innerText = myMonth[w][d]; } else { calDateText[((7*w)+d)-7].innerText = " "; } } } } // End --></script></head><!-- Вставьте эту часть кода в html документ --><BODY><script language="JavaScript" for=window event=onload><!-- Begin var dCurDate = new Date(); frmCalendarSample.tbSelMonth.options[dCurDate.getMonth()].selected = true; for (i = 0; i < frmCalendarSample.tbSelYear.length; i++) if (frmCalendarSample.tbSelYear.options[i].value == dCurDate.getFullYear()) frmCalendarSample.tbSelYear.options[i].selected = true; // End --></script><form name="frmCalendarSample" method="post" action=""><input type="hidden" name="calSelectedDate" value=""><table border="1"><tr><td><select name="tbSelMonth" onchange='fUpdateCal(frmCalendarSample.tbSelYear.value, frmCalendarSample.tbSelMonth.value)'><option value="1">Январь</option><option value="2">Февраль</option><option value="3">Март</option><option value="4">Апрель</option><option value="5">Май</option><option value="6">Июнь</option><option value="7">Июль</option><option value="8">Август</option><option value="9">Сентябрь</option><option value="10">Октябрь</option><option value="11">Ноябрь</option><option value="12">Декабрь</option></select> <select name="tbSelYear" onchange='fUpdateCal(frmCalendarSample.tbSelYear.value, frmCalendarSample.tbSelMonth.value)'><option value="2000">2000</option><option value="2001">2001</option><option value="2002">2002</option><option value="2003">2003</option><option value="2004">2004</option></select></td></tr><tr><td><script language="JavaScript">var dCurDate = new Date(); fDrawCal(dCurDate.getFullYear(), dCurDate.getMonth()+1, 30, 30, "12px", "bold", 1); </script></td></tr></table></form></body>
EXAMPLE-43 Electronic clock (24H)
<body onunload="cleartids()"><script language="LiveScript">function GoBack() { if (confirm("Are you sure you want to go to the previous page?")) { history.back() } } timestr = "00:00:00"; tid = 0; pause = 0; var to; var bcount; var tcount; function writer(){ document.write("test"); } function time(n) { tid=window.setTimeout("time(1)",to); today = new Date() if(today.getMinutes() < 10){ pad = "0"} else pad = ""; if(today.getSeconds() < 10){ pads = "0"} else pads = ""; timestr=today.getHours()+":"+pad+today.getMinutes()+":"+pads+today.getSeconds(); f.result.value = timestr; window.status = timestr; window.clearTimeout(tid); tid=window.setTimeout("time()",to); } function start(x) { f=x; to=60; time(x); } function cleartids() { window.clearTimeout(tid); } </script><form name="time"><input type="text" size="8" name="result" onfocus="this.blur()" style="text-align: center; font-family: sans-serif; font-size: 8pt; background-color: #DAFADE; color: rgb(255,0,0)"></form></body>
EXAMPLE-44 Electronic clock (AM / PM)
<BODY ><CENTER><span id=tick2></span><script> <!-- function show2(){ var Digital=new Date() var hours=Digital.getHours() var minutes=Digital.getMinutes() var seconds=Digital.getSeconds() var dn="AM" if (hours>12){ dn="PM" hours=hours-12 } if (hours==0) hours=12 if (minutes<=9) minutes="0"+minutes if (seconds<=9) seconds="0"+seconds var ctime="<b><font face='Verdana' color='#8000FF'>"+hours+":"+minutes+":"+seconds+" "+dn+"</font></b>" if (!document.all) document.write(ctime) else tick2.innerHTML=ctime } function loadclock(){ if (document.all) setInterval("show2()",1000) } if (!document.all) show2() //--></script></center></body>
EXAMPLE-45 Clock (24H)
Turned on after clicking
<head><script language=javaScript><!-- var hours var minutes var seconds function showtime() { var thistime= new Date() hours=thistime.getHours() minutes=thistime.getMinutes() seconds=thistime.getSeconds() if (eval(minutes) < 10) {minutes="0"+minutes} if (eval(seconds) < 10) {seconds="0"+seconds} if (eval(hours) < 10) {hours="0"+localhours} thistime = hours+":"+minutes+":"+seconds document.bigwatch.button.value=thistime var timer= setTimeout("showtime()",1000) } // - End of JavaScript - --></script></head><body bgcolor="#FFFFFF"><form name="bigwatch"><input name="button" type="button" value="ЧАСЫ !" onClick="showtime()" style="font-family:times;font-size:20pt;color:navy"></form></body>
EXAMPLE-46 Time in different cities
<head><script language=javaScript><!-- Beginning of JavaScript - var worldtime = new Array() worldtime[0]="Azores,-1" worldtime[1]="Baghdad,3" worldtime[2]="Beijing,8" worldtime[3]="Berlin,1" worldtime[4]="Buenos Aires,-3" worldtime[5]="Chicago,-6" worldtime[6]="Denver,-7" worldtime[7]="Hong Kong,8" worldtime[8]="Honolulu,-10" worldtime[9]="Johannesburg,2" worldtime[10]="Kairo,2" worldtime[11]="Lima,-5" worldtime[12]="London,0" worldtime[13]="Mexico City,-6" worldtime[14]="Moscow,4" worldtime[15]="New York,-5" worldtime[16]="Paris,1" worldtime[17]="Perth,8" worldtime[18]="Rio de Janheiro,-2" worldtime[19]="San Francisco,-8" worldtime[20]="Sydney,11" worldtime[21]="Tokyo,9" var hours var shifthours var minutes var seconds var localhours var pause=2000 var thisplace var thisline="" var showmenu=1 function showtime() { for (i=0; i<=worldtime.length-1;i++) { thisplace=worldtime[i].split(",") thistime= new Date() hours=thistime.getUTCHours() hours=eval(hours) shifthours=eval(thisplace[1]) localhours=eval(shifthours+hours) if (localhours <0) {localhours=24+localhours} if (localhours >=24) {localhours=localhours-24} minutes=thistime.getUTCMinutes() seconds=thistime.getUTCSeconds() if (thisplace[0]=='Delhi') { minutes=eval(minutes+30) if (minutes>=60) { minutes=eval(minutes-60) localhours=eval(localhours+1) } } if (eval(minutes) < 10) {minutes="0"+minutes} if (eval(seconds) < 10) {seconds="0"+seconds} if (eval(localhours) < 10) {localhours="0"+localhours} thisline+=localhours+":"+minutes+":"+seconds+" "+thisplace[0]+"<br>" } if (document.all) { timediv.innerHTML=thisline thisline="" var timer=setTimeout("showtime()",1000) } if (document.layers) { document.timediv.document.write("<span id='nn' class='timestyle'>") document.timediv.document.write(thisline) document.timediv.document.write("</span>") document.timediv.document.close() thisline="" } } function dblclick() { if (document.all && showmenu==1) { document.all.timediv.style.visibility="visible" document.all.timediv.style.posLeft=x document.all.timediv.style.posTop=y showtime() } if (document.layers && showmenu==1) { document.timediv.visibility="visible" document.timediv.left=x-40 document.timediv.top=y-80 showtime() } if (document.all && showmenu!=1) { document.all.timediv.style.visibility="hidden" } if (document.layers && showmenu!=1) { document.timediv.visibility="hidden" } showmenu=showmenu*-1 } if (document.layers) { document.captureEvents(Event.ONDBLCLICK); } document.ondblclick=dblclick; if (document.layers){ document.captureEvents(Event.MOUSEMOVE); } document.onmousemove = handlerMM; function handlerMM(e){ x = (document.layers) ? e.pageX : event.clientX y = (document.layers) ? e.pageY : event.clientY } // - End of JavaScript - --></script><STYLE>.timestyle { position:absolute; left:50px; top:100px; font-family:Verdana; font-size:8pt; color:880000; background-color:DDDDFF; } .explainstyle { position:absolute; left:10px; top:160px; font-family:Verdana; font-size:8pt; color:000000; } </STYLE></head><body bgcolor=#FFFFFF><DIV id=source class="explainstyle"><b>Часы появятся/исчезнут при двойном клике мышью</b>
EXAMPLE-47 World time in the status line
<head><script language=javaScript><!-- var worldtime = new Array() worldtime[0]="Azores,-2" worldtime[1]="Baghdad,3" worldtime[2]="Beijing,8" worldtime[3]="Berlin,2" worldtime[4]="Buenos Aires,-3" worldtime[5]="Chicago,-6" worldtime[6]="Denver,-7" worldtime[7]="Hong Kong,8" worldtime[8]="Honolulu,-10" worldtime[9]="Johannesburg,2" worldtime[10]="Kairo,2" worldtime[11]="Lima,-5" worldtime[12]="London,0" worldtime[13]="Mexico City,-6" worldtime[14]="Moscow,4" worldtime[15]="New York,-5" worldtime[16]="Paris,1" worldtime[17]="Perth,8" worldtime[18]="Rio de Janheiro,-3" worldtime[19]="San Francisco,-8" worldtime[20]="Sydney,11" worldtime[21]="Tokyo,9" // The speed of the ticker (milliseconds) var speed=1000 // The length of the steps var step=10 // Do not edit the variables below var hours var shifthours var minutes var seconds var localhours var thisplace var i_substring=0 var content function extracttime() { content=" -------------------------------------" for (i=0;i<=worldtime.length-1;i++) { thisplace=worldtime[i].split(",") thistime= new Date() hours=thistime.getUTCHours() hours=eval(hours) shifthours=eval(thisplace[1]) localhours=eval(shifthours+hours) if (localhours <0) {localhours=24+localhours} if (localhours >=24) {localhours=localhours-24} minutes=thistime.getUTCMinutes() seconds=thistime.getUTCSeconds() if (thisplace[0]=='Delhi') { minutes=eval(minutes+30) if (minutes>=60) { minutes=eval(minutes-60) localhours=eval(localhours+1) } } if (eval(minutes) < 10) {minutes="0"+minutes} if (eval(seconds) < 10) {seconds="0"+seconds} if (eval(localhours) < 10) {localhours="0"+localhours} thistime = localhours+":"+minutes content+=" ------ "+thisplace[0]+": "+thistime } content+=" -------------------------------------" scrolltime() } function scrolltime() { if (i_substring<=content.length-1) { window.status=content.substring(i_substring,content.length-1) i_substring=i_substring+step var timer=setTimeout("extracttime()",speed) } else { i_substring=0 clearTimeout(timer) extracttime() } } // - End of JavaScript - --></script></head><body bgcolor=#FFFFFF ><DIV ID="deletethisblock" class="redirstyle" style="position:absolute;left:10px;top:110px;color:000000;font-family:Verdana;font-size:10pt">Мировое время в строке статуса
EXAMPLE-48 Transparent clock
<head><script language=javaScript><!-- function clockon() { thistime= new Date() var hours=thistime.getHours() var minutes=thistime.getMinutes() var seconds=thistime.getSeconds() if (eval(hours) <10) {hours="0"+hours} if (eval(minutes) < 10) {minutes="0"+minutes} if (seconds < 10) {seconds="0"+seconds} thistime = hours+":"+minutes+":"+seconds if(document.all) { bgclocknoshade.innerHTML=thistime bgclockshade.innerHTML=thistime } if(document.layers) { document.bgclockshade.document.write('<div id="bgclockshade" style="position:absolute;visibility:visible;font-family:Verdana;color:FFAAAAA;font-size:120px;top:10px;left:12px">'+thistime+'
ALL FOR WEBMASTER | ||
JavaScript Examples | You created a new original project, posted it on a good hosting, set up counters, but they show only your visits day after day, as well as visits of your friends and colleagues.
What to do?
Can not anything be done?
Can!
If you are sure that your site looks like it does not repel its appearance,
|
Main Internet terms |
EXAMPLE-49 Calendar (1 month + time)
<HEAD> <title>Календарь</title> </HEAD><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#7F007F" ALINK="#FF0000"><SCRIPT LANGUAGE="JavaScript"><!-- setCal() function getTime() { // initialize time-related variables with current time settings var now = new Date() var hour = now.getHours() var minute = now.getMinutes() now = null var ampm = "" // validate hour values and set value of ampm if (hour >= 12) { hour -= 12 ampm = "PM" } else ampm = "AM" hour = (hour == 0) ? 12 : hour // add zero digit to a one digit minute if (minute < 10) minute = "0" + minute // do not parse this number! // return time string return hour + ":" + minute + " " + ampm } function leapYear(year) { if (year % 4 == 0) // basic rule return true // is leap year /* else */ // else not needed when statement is "return" return false // is not leap year } function getDays(month, year) { // create array to hold number of days in each month var ar = new Array(12) ar[0] = 31 // January ar[1] = (leapYear(year)) ? 29 : 28 // February ar[2] = 31 // March ar[3] = 30 // April ar[4] = 31 // May ar[5] = 30 // June ar[6] = 31 // July ar[7] = 31 // August ar[8] = 30 // September ar[9] = 31 // October ar[10] = 30 // November ar[11] = 31 // December // return number of days in the specified month (parameter) return ar[month] } function getMonthName(month) { // create array to hold name of each month var ar = new Array(12) ar[0] = "January" ar[1] = "February" ar[2] = "March" ar[3] = "April" ar[4] = "May" ar[5] = "June" ar[6] = "July" ar[7] = "August" ar[8] = "September" ar[9] = "October" ar[10] = "November" ar[11] = "December" // return name of specified month (parameter) return ar[month] } function setCal() { // standard time attributes var now = new Date() var year = now.getYear() var month = now.getMonth() var monthName = getMonthName(month) var date = now.getDate() now = null // create instance of first day of month, and extract the day on which it occurs var firstDayInstance = new Date(year, month, 1) var firstDay = firstDayInstance.getDay() firstDayInstance = null // number of days in current month var days = getDays(month, year) // call function to draw calendar drawCal(firstDay + 0, days, date, monthName, 0 + year) } function drawCal(firstDay, lastDate, date, monthName, year) { // constant table settings var headerHeight = 50 // height of the table's header cell var border = 2 // 3D height of table's border var cellspacing = 4 // width of table's border var headerColor = "midnightblue" // color of table's header var headerSize = "+3" // size of tables header font var colWidth = 50 // width of columns in table var dayCellHeight = 25 // height of cells containing days of the week var dayColor = "darkblue" // color of font representing week days var cellHeight = 40 // height of cells representing dates in the calendar var todayColor = "red" // color specifying today's date in the calendar var timeColor = "purple" // color of font representing current time // create basic table structure var text = "" // initialize accumulative variable to empty string text += '<CENTER>' text += '<TABLE BORDER=' + border + ' CELLSPACING=' + cellspacing + '>' // table settings text += '<TH COLSPAN=7 HEIGHT=' + headerHeight + '>' // create table header cell text += '<FONT COLOR="' + headerColor + '" SIZE=' + headerSize + '>' // set font for table header text += monthName + ' ' + year text += '</FONT>' // close table header's font settings text += '</TH>' // close header cell // variables to hold constant settings var openCol = '<TD WIDTH=' + colWidth + ' HEIGHT=' + dayCellHeight + '>' openCol += '<FONT COLOR="' + dayColor + '">' var closeCol = '</FONT></TD>' // create array of abbreviated day names var weekDay = new Array(7) weekDay[0] = "Sun" weekDay[1] = "Mon" weekDay[2] = "Tues" weekDay[3] = "Wed" weekDay[4] = "Thu" weekDay[5] = "Fri" weekDay[6] = "Sat" // create first row of table to set column width and specify week day text += '<TR ALIGN="center" VALIGN="center">' for (var dayNum = 0; dayNum < 7; ++dayNum) { text += openCol + weekDay[dayNum] + closeCol } text += '</TR>' // declaration and initialization of two variables to help with tables var digit = 1 var curCell = 1 for (var row = 1; row <= Math.ceil((lastDate + firstDay - 1) / 7); ++row) { text += '<TR ALIGN="right" VALIGN="top">' for (var col = 1; col <= 7; ++col) { if (digit > lastDate) break if (curCell < firstDay) { text += '<TD></TD>' curCell++ } else { if (digit == date) { // current cell represent today's date text += '<TD HEIGHT=' + cellHeight + '>' text += '<FONT COLOR="' + todayColor + '">' text += digit text += '</FONT><br>' text += '<FONT COLOR="' + timeColor + '" SIZE=2>' text += '<CENTER>' + getTime() + '</CENTER>' text += '</FONT>' text += '</TD>' } else text += '<TD HEIGHT=' + cellHeight + '>' + digit + '</TD>' digit++ } } text += '</TR>' } // close all basic table tags text += '</TABLE>' text += '</CENTER>' // print accumulative HTML string document.write(text) } // --></SCRIPT></BODY>
EXAMPLE-50 Number, time in words
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#7F007F" ALINK="#FF0000"> <SCRIPT LANGUAGE="JavaScript">current_date = new Date(); document.write("<p><i>Текуща\я дата:</i> " + current_date + ".<p>"); </SCRIPT> <br>Также можно вывести сокращенный вариант для этого используются методы getDate, getMonth, getYear. Обратите внимание, что нумерация месяцев начинается с нуля. <SCRIPT LANGUAGE="JavaScript">current_date = new Date(); document.write("<p><i>Число:</i> " + current_date.getDate() + "." + current_date.getMonth() + "." + current_date.getYear() + ".<p>"); </SCRIPT><br>Или такой вариант: <SCRIPT LANGUAGE="JavaScript">current_date = new Date(); document.write("<p><i>Врем\я:</i> " + current_date.getHours() + "." + current_date.getMinutes() + "." + current_date.getSeconds() + ".<p>"); </SCRIPT> </BODY>
Comments
When commenting on, remember that the content and tone of your message can hurt the feelings of real people, show respect and tolerance to your interlocutors even if you do not share their opinion, your behavior in the conditions of freedom of expression and anonymity provided by the Internet, changes Not only virtual, but also the real world. All comments are hidden from the index, spam is controlled.