Sometimes you want to run the same script on many pages. In this case, you'll write a JavaScript as an external file. Then, simply call the .js file when you need it. It's similar to the way you "call" your CSS file. You use the <script> start and end tags within the HTML document to call this .js file. Like CSS, you DO NOT include the <script> tag in an external JavaScript.

Check out examples at Landmarks JavaScript.


Footers are a good use of an external javascript. You'd put the following script in your HTML document.

<script src="footer.js"></script>

Then, create the JavaScript file in Dreamweaver or a text editor. Simply save the document with the .js file extension. For an example, go to footer1.js to see the example below:

document.write("All Rights Reserved. Copyright 2006.");

You can add some text and today's date. For an example, go to footer2.js.

var today = new Date();
document.write('Based on the Internet clock ' + today.toLocaleString() );

You can also add a graphic in addition to text. For an example, go to footer3.js.

document.write("<img src='logo.jpg'> Enjoy this student-produced page.");

| eduscapes | IUPUI Online Courses | Teacher Tap | 42explore | escrapbooking | About Us | Contact Us | ©2006-2011 Annette Lamb and Larry Johnson