Javascript Notes
Basic Notes for Javascript
Contents
Full documentation of Javascript can be found at Mozilla Developer Center
Running Javascript Statements
Top BottomJavascript expressions can be intepreted by javascript to produce a value. By combining basic expressions (literals or variable names) with operators, complex statements and scripts can be built.
Most modern browsers come with javascript interpreters. You can run a javascript one-liner in the address bar by pre-pending 'javascript:' before statement. Enter 'javascript:alert("Hello World") in the address bar of Firefox, to produce a 'Hello World' pop-up. The Firebug add-on, allows you to edit and execute larger scripts. jslint provides basic syntax checking.
To include javascript in an HTML document:
- enclose the script within a <script> tag with type attribute of 'text/javascript'
- use HTML event-handler attributes (eg. onclick, onmouseover, ...)
- use javascript URLs
In the interests of keeping content and behaviour seperate, and to meet the stricter specifications of XHTML, place your javascript in an external file and link to it in the header of your XHTML
<script type="text/javascript" src="javascript/fancyDOMstuff.js"></script>
