![]() |
| Linking to Javascript |
| There are two ways to include Javascript routines within your web page. The first is to embed the routine within the pages HTML as shown below: |
<script language="javascript" type="text/javascript">
var d = new Date(document.lastModified)
d = d.toUTCString().substr(0,16);
document.write("page last updated on " + d)
</script>
|
| The above routine displays the date the page was last updated.
The other method is to include your Javascript code in a separate file. The reasoning behind this is identical to using a separate style sheet file. Any routines that are referenced from more than one page only need to be entered once. In addition if you need to amend a routine on a number of pages you can be sure that you'll not do them all correctly. By using a separate Javascript file the routine need only be amended once. To reference a Javascript file, include the following statement within your HTML <HEAD> tags: |
| <script language"javascript" src="scripts.js" type="text/javascript"></script> |
| where src points to your Javascript file. You then only need to call your routine from within your HTML. |