These javascript snippets can be cut and pasted into your page with little or no alteration. To copy the scripts highlight them with your mouse and then press the [Ctrl] & [C] keys simultaneously to copy them to the clipboard. The script can then be pasted into your application.
Microsoft Smart Tags
Windows XP and IE6+ technology allows Microsoft to insert links in your Web Pages without your knowledge or permission. Luckily this function can be disabled by pasting the following tag into the head of your document.
Automatic Print Script
This is a super-easy little script that you can use to form an automatic print-page link on your site. Just insert this script where you want the link to display and your visitors can choose to print the page they are viewing.
<a href='javascript:;' onClick='window.print();return false'>Print this
page.</a>
No Right Click
Place this script between the head tags. You can change the wording in Red.
Just be aware that these "no right click" type scripts only deter the inexperienced user.
There are many ways around them.
<script LANGUAGE="JavaScript">
<!--
function click() {
if (event.button==2) {
alert('Right Click Option Not Available!');
}
}
document.onmousedown=click
// -->
</script>
Bookmark Page
Paste this snippet in the body of your document where you want the link to appear. Change the script in Red.
<a href="javascript:window.external.AddFavorite('http://www.yoursite.com/', 'My Site Title');">Bookmark This Site!</a>
This script only works for IE5+ browsers.
No Frills Popup
Just copy and paste this into the head of your document changing the script in Red.
Updating Copyright Notice
This copyright notice palces the current year on the page so that copyright notices are always current. Once it's on your page there is no need to update the script.
Add the current date to your page.
This script will add the date in the form dd month yyyy (eg. 7 January 2000). Just copy and paste it into the document where you want it to appear.
<script language="JavaScript">
<!--
function makeArray() {
for (i = 0; i<makeArray.arguments.length; i++)
this[i + 1] = makeArray.arguments[i];
}
var months = new makeArray('January','February','March','April','May','June', 'July','August','September','October','November','December');
var date = new Date();
var day = date.getDate();
var month = date.getMonth() + 1;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;
document.write(day + " " + months[month] + " " + year);
//-->
</script>
Example
Document Last Modified (a more readable version)
Insert this code in your document where you want the page last modified date to appear.
<script language = 'JavaScript'>
<!--
function makeArray0() {
for (i = 0; i<makeArray0.arguments.length; i++)
this[i] = makeArray0.arguments[i];
}
var days = new makeArray0("Sunday","Monday","Tuesday","Wednesday","Thursday" ,"Friday","Saturday");
var months = new makeArray0('January','February','March','April','May','June', 'July','August','September','October','November','December');
function nths(day) {
if (day == 1 || day == 21 || day == 31) return 'st';
if (day == 2 || day == 22) return 'nd';
if (day == 3 || day == 23) return 'rd';
return 'th';
}
function getCorrectedYear(year) {
year = year - 0;
if (year < 70) return (2000 + year);
if (year < 1900) return (1900 + year);
return year;
}
function y2k(number) { return (number < 1000) ? number + 1900 : number; }
function padout(number) { return (number < 10) ? '0' + number : number; }
var last = document.lastModified;
var date = new Date(last);
var dateY2K = new Date(getCorrectedYear(date.getYear()),date.getMonth(),date.getDate());
document.write('Last Modified: '+ days[dateY2K.getDay()] + ' ' +
dateY2K.getDate() + nths(dateY2K.getDate()) + " " +
months[dateY2K.getMonth()] + ", " +
(y2k(dateY2K.getYear()))
);
//-->
</script>
Example
Break Out Of Frames
Use this script in between the <head></head> tags of your document to automatically bust out of other peoples frames.
Add an internet search box to your site.
Your visitors will be able to search the WWW (via multiple search engines) and a KIDSAFE search engine (Yahooligans). Just copy and paste the following script into your document and you will have your visitors returning to your site every time they are looking for something on the WWW.
The Super Search Box will appear on your page just as the working copy does at the bottom of this page.
Page Formatting Note: The Super Search Box script generates a table that is 230 pixels wide. If you cannot fit it in a table cell on your existing page you may need to paste the code at the bottom of your page or, alternatively, on it's own page.
Due to the style sheets used in Webmaster Tools your search box may have a slightly different look.
Window Maximiser
Place this script in the head of any document that you want to be maximised.
Keep Window In Focus
Use this code to make sure a window remains in focus, on top. Great for web site news or smaller popup windows that are easily shuffled under out of focus.
<body onblur="self.focus();">
Allow Users To Save Your Page To Their Hard Drive
IE4+ browsers have a function that allows you to call the SaveAs dialog
to save a web page. The following script includes an alternate alert message for non-IE browsers.
Paste the following script in the head of of your document.
<script language="JavaScript">
<!--
var isReady = false;
function doSaveAs(){
if (document.execCommand){
if (isReady){document.execCommand("SaveAs");}
}else{
alert('Feature available only in Internet Exlorer 4.0 and later.');
}
}
//-->
</script>
Include the following onload event call in the body tag. This stops
the page being saved until it is fully loaded.
<body onload="isReady=true">
To call the script from the page and activate the SaveAs dialog,
insert a link in the page like this:
<a href="javascript:doSaveAs()">
Click Here To Save This Page
</a>
Show users where on your site they currently located.
Example:
The results you get from a page on your hard drive will obviously be different to those from your web site.
Insert the following code in the body of each document where you want the information to appear. No code changes are necessary.
<BODY OnLoad="window.defaultStatus='Put Your Message Here!';">
Text Area Background
Copy and paste this script into the body of your document where you want the effect to appear. Then just change the code in RED eg. var message, the typingbasecolor and the typingtextcolor for a great effect. You can also change blinkspeed, fontface and fontsize to further personalise the script. The rest of the script should remain unchanged.
<script language="JavaScript1.2">
var message="EreNeT.NeT Eğlencenin Merkezi.."
var typingbasecolor="ececec"
var typingtextcolor="ff00ff"
var blinkspeed=100
var fontface="arial,geneva,helvetica"
var fontsize="5"
var n=0
if (document.all){
document.write('<font face="'+fontface+'" size="'+fontsize+'" color="'+typingbasecolor+'">')
for (m=0;m<message.length;m++)
document.write('<span id="typinglight">'+message.charAt(m)+'</span>')
document.write('</font>')
var tempref=document.all.typinglight
}
else
document.write(message)
function typing(){
if (n==0){
for (m=0;m<message.length;m++)
tempref[m].style.color=typingbasecolor
}
tempref[n].style.color=typingtextcolor
if (n<tempref.length-1)
n++
else{
n=0
clearInterval(blinking)
setTimeout("starttyping()",1500)
return
}
}
function starttyping(){
if (document.all)
blinking=setInterval("typing()",blinkspeed)
}
starttyping()
</script>
Background Fireworks.
Just copy and paste this script anywhere in the body of your document for a dynamic background effect. There is no need to change any code. It will work best with a dark background in your document.
Cross Browser Background Sound
Copy and paste this script into the body of your document. Just change the name of the mid file.
<SCRIPT LANGUAGE="JavaScript">
<!--
var MSIE=navigator.userAgent.indexOf("MSIE");
var NETS=navigator.userAgent.indexOf("Netscape");
var OPER=navigator.userAgent.indexOf("Opera");
if((MSIE>-1) || (OPER>-1)) {
document.write("<BGSOUND SRC=mysong.mid LOOP=INFINITE>");
} else {
document.write("<EMBED SRC=mysong.mid AUTOSTART=TRUE ");
document.write("HIDDEN=true VOLUME=100 LOOP=TRUE>");
}
//-->
</SCRIPT>
Simple Image Change For Time Of Day
This script will show an image of your choice depending on the viewers time. If it is between 6am and 6pm they get one image and if its between 6pm and 6am they get another. In the following example you will see a sun if it is between 6am and 6pm or a moon otherwise. Just change the URL for your images and paste the code where you want the image to appear. The script works on a 24 hour clock. You can change the hours (in red) to suit your needs. It will work best if the images are the same size.
<script language="javascript">
<!--
var cur= new Date()
var change=cur.getHours()
if ((change<18) && (change>=6))
document.write("<img src='sun.gif'>")
else
document.write("<img src='moon.gif'>")
//-->
</script>
WWW Jump Box
Give your visitors a jump box so that they can access anywhere on the WWW from your page.