The following pages contain help, examples, advice and links to all things Javascript.
Not sure what Javascript is? Well, we use it a lot, but sparingly! Javascript is an incredibly useful tool for any website, and many websites rely on it.
So what does it do? It can put a clock on your website that runs off your computers clock, but displays it on a web page. That's the easy stuff. It can also put a scrolling marquee on your site, put words into bottom line of your browser (and scroll them), re-direct visitors to a page you have designed in Netscape or one designed in Explorer - automatically!
But that just touches on the subject.
There are literally hundreds of pre-written and tested Javascripts available and we will try to list as many of the good sources as possible.
We can show you a few examples here. Bear in mind with Javascript that you usually have to put a line or two of text in the <HEAD> section of your HTML code, and the 'working' bit in the <BODY> section. If you are unsure how to do this, please refer to the HTML pages first.
Here are a few examples of common Javascripts that are really easy to implement.
No Right-Click If you have loads of bespoke graphics on your site that you don't want 'right-clickers' to take off your pages, then this script will help. Copy and paste the code into the <BODY> of your HTML page.
<script language=JavaScript>
var message="Sorry, right click function disabled";
function click(e) {
if (document.all) {
if (event.button==2||event.button==3) {
alert(message);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
</script>
You can change the red part to say anything you want to show in the alert box that jumps up when the page is right-clicked - keep it clean though!
Simply cut and paste everything below onto your page (inside the <body> tags, wherever you want the clock to sit), and you're done! Script courtesy of Website Abstract
<form name="Tick">
<input type="text" size="11" name="Clock">
</form>
<script>
<!--
/*By George Chiang (WA's JavaScript tutorial)
http://wsabstract.com
Credit must stay intact for use*/
function show(){
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
document.Tick.Clock.value=hours+":"+minutes+":"
+seconds+" "+dn
setTimeout("show()",1000)
}
show()
//-->
</script>
You will notice when you have pasted the code onto your page that a 'credit' shows up highlighted in yellow. One of the rules for copying anyone else's work given freely is that a credit for the work remains intact.
Please help to spread the word about any script author by keeping this in place! (In this case George Chiang through Website Abstraction).
Drop-Down Boxes That was easy wasn't it? Now let's move onto something a bit more advanced. Lets look at how your visitors move around your site. Some sites use 'Combo Boxes' - you will have seen them before, they are sometimes called 'drop-down boxes' and look something like this:
The letters written in red should be changed to the name of the destination page on your own website. If you want them to link to pages NOT on your website, this can be done too!
Change <option value="tables.html">Tables
To <option value="http://www.destination.com">Destination
One important addition! You have to add the following script between <HEAD> and </HEAD> section of your page otherwise it won't work.
<script>
function formHandler(form){
var URL = document.form.site.options[document.form.site.selectedIndex].value;
window.location.href = URL;
}
</SCRIPT>
Now for something really clever! Still on drop-down boxes, you can do away with the box,