Javascripts

here are a collection of javascripts for you to use on your site.

Remember there are two ways to use these samples. You can copy and paste them exactly as they are into your webpage where you want them or you can make a seperate file. To make them a seperate file you remove everything before, and including the "<!--" bit from the start and everything from, and including, the "// -->" bit from the end. Then save whats left into a file and save it with the extension .js. Then you simply place the following tag in your html where you want the javascript to be used remebering to change NAME for the name you gave the file.

<script language="javaScript" type="text/javascript" src="NAME.js"></script>

Browser Detection

This is a script to display your browser:

<script language="javaScript" type="text/javascript">
<!--
var useragent = navigator.userAgent; 
var bName = (useragent.indexOf('Opera') > -1) ? 'Opera' : navigator.appName; 
var pos = useragent.indexOf('MSIE'); 
if (pos > -1) { 
   bVer = useragent.substring(pos + 5); 
   var pos = bVer.indexOf(';'); 
   var bVer = bVer.substring(0,pos); 
} 
var pos = useragent.indexOf('Opera'); 
if (pos > -1)    { 
   bVer = useragent.substring(pos + 6); 
   var pos = bVer.indexOf(' '); 
   var bVer = bVer.substring(0, pos); 
} 
if (bName == "Netscape") { 
   var bVer = useragent.substring(8); 
   var pos = bVer.indexOf(' '); 
   var bVer = bVer.substring(0, pos); 
} 
if (bName == "Netscape" && parseInt(navigator.appVersion) >= 5) { 
   var pos = useragent.lastIndexOf('/'); 
   var bVer = useragent.substring(pos + 1); 
} 
document.writeln('<strong>Browser : ' + bName + ' ' + bVer +  '</strong>') 
// -->
</script>

You can edit the document.writeln part to your desired HTML

No Right Click

Add this code to the BODY section of your pages

<script language="javaScript" type="text/javascript">
<--
var message="";
///////////////////////////////////
function clickIE() {if (document.all) {(message);return false;}}
function clickNS(e) {if 
(document.layers||(document.getElementById&&!document.all)) {
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers) 
{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}

document.oncontextmenu=new Function("return false")
// -->
</script>


Frame Busting

Prevent other sites form showing your pages in a frame by putting this in the HEAD section of your pages. It only works for people viewing in IE though, which is the vast majority really.

<script language="javaScript" type="text/javascript">
<!--
var caught = 0;
if (top.frames.length != 0)
{
caught++;
if (caught != 0)
{
top.location=self.document.location;
}
}
// -->
</script>


Other Recommended Scripts

We recommend Dynamic Drive as a good source of javascripts


Want some naughty smileys for your Yahoo messenger? Then look HERE.