Main | Basic | Advanced | Download | |||||
Introduction to JavaScript
JavaScript is used to do things like when you want to bring up a confirm dialog box, move an object with Dynamic HTML, or bring up an alert dialog box. It is an offshoot of the programming language JAVA, and was invented by Netscape. JavaScript can be incorporated into the code of an HTML document, which makes it very useful in web design terms. There are many different properties, methods, and so on, and I am not going to go over them all here. Instead, here are a few of the more simple and useful features the language offers for web designers.
JavaScript uses what are called event handlers, which execute a set of an instructions when an event takes place, like the user clicks something. The ones we will be using are:
OnClick
JavaScript is not recognised by old browsers, if they don't take frames they certainly won't take JScript. If we just wrote the code within the two tags <SCRIPT> & </SCRIPT> then an old browser would not recognise the tags and just take the language as being normal text to be printed in the web page, and it would come up. This presents an easily solved problem of how to prevent this happening: The answer is to use comment tags round the code, as new browsers will execute anything within the SCRIPT tags regardless of comment tags, and old browsers will skip the SCRIPT tags and take the code as a comment.
Alerts:
Where anyname is the name of the function that will be executed when the event that calls it happens.
<A HREF="anyname()"> A link with an alert when you click on it. </A>
This does not need the OnClick event handler because when you click on a link the browser goes to that page or executes that function without being told "On Click do this".
<FORM>
Confirm Dialogs:
<SCRIPT>
This brings us to the subject of the "location" statement, which specifies what file to go to if the user chooses OK, in this case the MIDI file dcodys.mid. If the user chooses cancel nothing happens and they can continue to browse.
<HTML>
The OnMouseOver Statement:
<A HREF="apage.htm" OnMouseOver="self.status='A link to apage.htm'; return true;"> A link to a page </A>
You can use these methods for practically anything in an HTML page, images, buttons, checkboxes.....
|
Copyright 1998 Iceman. All Rights Reserved. Further Legal Stuff
This page hosted by Get your own Free Home Page