Java Scripts Collection A collection of scripts
The following example can replace a script that controls the background color, text and links directly from the web page. The visitor of the page will only need to click on one of the cells here for such a small table:
__ | __ | __ | __ | __ | __ | __ |
At the basis of this method is the mouse click control command - span onClick = "..." that's the actual code itself (here code only one cell of the table):
<table style="CURSOR: hand" align=center bgcolor= ... >
<tbody> <tr> <td bgcolor=#C8CECD width="20" height="13">
<span onClick="bgColor=' #C8CECD '; fgColor=' #000000 '; linkColor=' #0000СС '; vlinkColor=' #9900СС '"> <font color="#000000">__</font>
</span> </td>
... </tr> </tbody>
</table>
This is the simplest script for setting a password on a web page. Paste into the <HEAD> tag. Here the password value is "name", but you can replace it with any other (uppercase letters are taken into account):
<script laguage=JavaScript> <br> pass = prompt('Введите пароль');<br> if (pass=='name') { alert('Пароль верный') } <br> else { alert('Неверный пароль!'), top.location.href="/click?http://" }<br> </script> <br>
This script displays a greeting, a date and a day of the week, depending on the current time of day:
<script type=text/JavaScript> function priv() { var dt = new Date(); var nt = dt.getHours(); var hs = ''; if ( nt>=0 && nt<6 ) hs="Доброй ночи!"; if ( nt>=6 && nt<11 ) hs="Доброе утро!"; if ( nt>=11 && nt<18 ) hs="Добрый день!"; if ( nt>=18 ) hs="Добрый вечер!"; return hs; } function dat() { var k = ''; var Day = ''; var Month = ''; var now = new Date(); var pr = now.getYear(); var yr = 2000; var mName = now.getMonth() + 1; var dName = now.getDay() + 1; var dayNr = ((now.getDate()<10) ? "0" : "") + now.getDate(); pr = (pr % 100); if(pr==3) k="2003"; if(pr==4) k="2004"; if(pr==5) k="2005"; if(pr==6) k="2006"; if(pr==7) k="2007"; if(pr==8) k="2008"; if(pr==9) k="2009"; if(pr==10) k="2010"; if(pr==11) k="2011"; if(pr==12) k="2012"; if(pr==13) k="2013"; if(pr==14) k="2014"; if(dName==1) Day = "Воскресенье"; if(dName==2) Day = "Понедельник"; if(dName==3) Day = "Вторник"; if(dName==4) Day = "Среда"; if(dName==5) Day = "Четверг"; if(dName==6) Day = "Пятница"; if(dName==7) Day = "Суббота"; if(mName==1) Month="января"; if(mName==2) Month="февраля"; if(mName==3) Month="марта"; if(mName==4) Month="апреля"; if(mName==5) Month="мая"; if(mName==6) Month="июня"; if(mName==7) Month="июля"; if(mName==8) Month="августа"; if(mName==9) Month="сентября"; if(mName==10) Month="октября"; if(mName==11) Month="ноября"; if(mName==12) Month="декабря"; var nnn =(""+dayNr+" "+Month+" " + k + " года" + " - " + Day); document.open(); return nnn; } function ALZ(s) { return (s<10?"0":"")+s.toString(); } function C2UT(s) { d=new Date(s); return ALZ(d.getDate())+"."+ALZ(d.getMonth()+1)+"."+d.getFullYear()+" " +ALZ(d.getHours())+":"+ALZ(d.getMinutes()); } </script> <script>document.writeln(priv());</script> <script>document.writeln(dat());</script>
Example:
A simple script output date and running hours:
<Script laguage=JavaScript> function fulltime() { var time=new Date(); document.clock.full.value=time.toLocaleString(); setTimeout('fulltime()',500) } </script> <form name=clock> <input type=text size=20 name=full> </form> <script laguage=JavaScript>fulltime(); </script>
A script that blocks a pop-up menu on the page when you right-click a mouse:
<SCRIPT>function click() { if(event.button==2) {alert("..если хочешь - сохраняй всю страницу, а по частям не дам.. <img src="/img/skin/smiles/smile.png" alt=":)">"); } } document.onmousedown=click; </SCRIPT>
To output the date and time of page editing, insert (before the script specify the font tag):
Example:
<script language=JavaScript> d = new Date(); t = Date.parse(document.lastModified); r = Math.round((dt)/86400000); document.write("Сегодня "); document.write(d.toLocaleString()); </script>
You can kill the advertising banner of the Host from the People by simply adding the following code (after the </ html> tag) at the end of the page:
<noscript><noscript>
<plaintext><plaintext>
And here's another script, which in the bottom (status) panel of the browser spells out the title of your page:
<SCRIPT><!-- var tit = document.title; var c = 0; function writetitle() {document.title = tit.substring(0,c); if(c==tit.length) {c = 0; setTimeout("writetitle()", 3000) } else{ c++; setTimeout("writetitle()", 200) }}writetitle() // --> </SCRIPT>
The following Java script is interesting in that it allows you to create a simple search on the pages of your site, even on a host that does not support Php, Perl, and similar dhtml scripts. The only inconvenience is that in the script itself you will have to enter data about the contents of your pages in the following format: c ++; Item [c] = new Array ("address.htm", "", "page name", "keywords", "description"); For pages not specified in the script, the search will not be carried out naturally. The script code must be inserted before the </ head> tag of your page:
<SCRIPT LANGUAGE="JavaScript"><!-- var item = new Array(); // "имя","путь","название","ключевые,слова","описание страницы" c=0; item[c]=new Array("Y-net.narod.htm","","Введение","скачать, поиск, html, форум, веб, сайт, редактор, раскрутка, каталог","Редакторы, поиск, html"); c++; item[c]=new Array("y.htm","","название","слова","описание"); c++; item[c]=new Array("y.htm","","название","слова","описание"); c++; item[c]=new Array("y.htm","","название","слова","описание"); function search(frm) { win = window.open("","","width=500,height=400,resizable=yes,scrollbars=yes,status=1"); txt = frm.searchtext.value.split(" "); page="<html><head><title>Результат поиска "+txt+"</title><META content='text/html; charset=windows-1251' http-equiv=Content-Type><LINK href=\"/develop/js/styles.css\" rel=STYLESHEET type=text/css>\n</head>\n<BODY link=#2288DD aLink=#ff0000 vLink=#ff0033 leftMargin=2 topMargin=0 MARGINHEIGHT=0 MARGINWIDTH=2><center><table border=0 cellspacing=10 width=80%>"; win.document.write(page); fnd = new Array(); total=0; for (i = 0; i < item.length; i++) { fnd[i] = 0; order = new Array(0, 4, 2, 3); for (j = 0; j < order.length; j++) for (k = 0; k < txt.length; k++) if (item[i][order[j]].toLowerCase().indexOf(txt[k]) > -1 && txt[k] != "") fnd[i] += (j+1); } for (i = 0; i < fnd.length; i++) { n = 0; w = -1; for (j = 0;j < fnd.length; j++) if (fnd[j] > n) { n = fnd[j]; w = j; }; if (w > -1) total += show(w, win, n); fnd[w] = 0; } win.document.write("</table><br><small>Всего найдено страниц : <b>"+total+"</b> c словом <b><font color=red>"+txt+"</font><br></body></html>"); win.document.close(); } function show(which,wind,num) { link = item[which][1] + item[which][0]; line = "<tr><td><small><a href='"+link+"'>"+item[which][2]+"</a> Совпадений: "+num+"<br>"; line += item[which][4] + "<br>"+link+"</td></tr>"; wind.document.write(line); return 1; } //--></script>
The very form of the search is inserted into any place of the page with the following code:
<FORM method=get action="javascript:void(0)" onsubmit="search(this); return false;">
<input class=inputbox type=text name=searchtext value="html" size="30">
<input class=button type=submit value=" Поиск по сайту ">
</FORM>
The search result displays links and page names, as well as how many times this word appears on each of the pages found. Here is an example of how this script works:
Example (forms only):
The following script considers the age of the site in days, you only need to change the date of creation of the site and the text of the output line:
<script language=JavaScript>d0 = new Date('January 11, 2003'); d1 = new Date(); dt = (d1.getTime() - d0.getTime()) / (1000*60*60*24); document.write('<SMALL>'); document.write('Этому сайту исполнилось <B>' + Math.round(dt) + '</B> дней.'); document.write('</SMALL>'); </script>
The script of your banner network, in other words this script displays a random banner from the list specified in it. For each banner there are two parameters - the link address and the path to the gif image:
This [1] = "http: // link_01";
This [2] = "banner_01.gif";
// <!-- Main function banners() { this[1]="http://ссылка01"; this[2]="banner01.gif"; this[3]="http://ссылка02"; this[4]="banner02.gif"; this[5]="http://ссылка03"; this[6]="banner03.gif"; if ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion.substring(0,1)) < 3)) { return(' '); } var j=(new Date()).getSeconds() % 3; document.write('<a href=' + this[2*j+1] + ' target=blank><img src=' + this[2*j+2] + ' border=0 width=88 height=31></a>'); return(' '); } // --></SCRIPT><SCRIPT language=JavaScript>// <!-- Main banners(); // --></SCRIPT>
Do not forget to also specify the number of your banners (here j = 3) in the following line: var j = (new Date ()). GetSeconds ()% 3;
This script is the original clock with a dial (example in the lower right corner):
<!-- fCol='444444'; //face colour. sCol='CC0000'; //seconds colour. mCol='444444'; //minutes colour. hCol='444444'; //hours colour. Ybase=28; //Clock height. Xbase=28; //Clock width. H='...'; H=H.split(''); M='....'; M=M.split(''); S='.....'; S=S.split(''); IE4=(document.all); Ypos=0; Xpos=0; dots=12; Split=360/dots; if (IE4){ document.write('<div style="position:absolute;top:0px;left:0px"><div style="position:relative">'); for (i=1; i < dots+1; i++){ document.write('<div id="ieDigits" style="position:absolute;top:0px;left:0px;width:30px;height:30px;font-family:Arial;font-size:10px;color:'+fCol+';text-align:center;padding-top:10px">'+i+'</code>'); } document.write('</div></div>') document.write('<div style="position:absolute;top:0px;left:0px"><div style="position:relative">'); for (i=0; i < M.length; i++){ document.write('<div id=y style="position:absolute;width:2px;height:2px;font-size:2px;background:'+mCol+'"></div>'); } document.write('</div></div>') document.write('<div style="position:absolute;top:0px;left:0px"><div style="position:relative">'); for (i=0; i < H.length; i++){ document.write('<div id=z style="position:absolute;width:2px;height:2px;font-size:2px;background:'+hCol+'"></div>'); } document.write('</div></div>') document.write('<div style="position:absolute;top:0px;left:0px"><div style="position:relative">'); for (i=0; i < S.length; i++){ document.write('<div id=x style="position:absolute;width:2px;height:2px;font-size:2px;background:'+sCol+'"></div>'); } document.write('</div></div>') } function clock(){ time = new Date (); secs = time.getSeconds(); sec = -1.57 + Math.PI * secs/30; mins = time.getMinutes(); min = -1.57 + Math.PI * mins/30; hr = time.getHours(); hrs = -1.57 + Math.PI * hr/6 + Math.PI*parseInt(time.getMinutes())/360; if (IE4){ Ypos=document.body.scrollTop+window.document.body.clientHeight-Ybase-10; Xpos=document.body.scrollLeft+window.document.body.clientWidth-Xbase-10; for (i=0; i < dots; ++i){ ieDigits[i].style.pixelTop=Ypos-15+Ybase*Math.sin(-1.045 +i *Split*Math.PI/180) ieDigits[i].style.pixelLeft=Xpos-15+Xbase*Math.cos(-1.045 +i *Split*Math.PI/180) } for (i=0; i < S.length; i++){ x[i].style.pixelTop =Ypos+i*Ybase/4.1*Math.sin(sec); x[i].style.pixelLeft=Xpos+i*Xbase/4.1*Math.cos(sec); } for (i=0; i < M.length; i++){ y[i].style.pixelTop =Ypos+i*Ybase/4.1*Math.sin(min); y[i].style.pixelLeft=Xpos+i*Xbase/4.1*Math.cos(min); } for (i=0; i < H.length; i++){ z[i].style.pixelTop =Ypos+i*Ybase/4.1*Math.sin(hrs); z[i].style.pixelLeft=Xpos+i*Xbase/4.1*Math.cos(hrs); } } setTimeout('clock()',100); } clock(); //--></SCRIPT>
In the first 6 lines of the script you can change the color of any element and the size of the clock.
The output coordinates can be adjusted by changing the two numbers in the last block of the script:
Ypos = document.body.scrollTop + window.document.body.clientHeight-Ybase-10;
Xpos = document.body.scrollLeft + window.document.body.clientWidth-Xbase-10;
Comments
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.