So, what do these special tags look like? They look like a plain script tag, but they use an extra attribute: The SRC="http://someplace.com/script_name.js" attribute.
Here is an example of one of these tags:
So, let's give it a try. Open a new document in your text editor, and write the following code into it:
function a_message() |
alert('I came from an external script! Ha, Ha, Ha!!!!');
Now, save the file as "jxt1.js".
You can now use this script on any page you place the special script tags on. Place the script tags inside your <HEAD></HEAD> tags. Be sure the SRC attribute points to your .js file. If you are working in one directory, just use the tag this way:
If not, try an absolute url. Be sure to change this to your domain and the correct directory:
Now, you can call your message function from the page that you placed the tags on. I will use a link as an example:
I used the same script for this example, clicking on the link will bring up our message from the external script. (If you are not familiar with this kind of link tag, see the JS link tutorial for details.
This script is not very useful, it will just give you one alert message to use on every page (Yuck!). However, it shows you how to call a function from an external script (just like a normal function). I'm sure you can think of some better scripts to use with this. (Actually, I can too, but I'm too lazy to type out a long script here...).
Well, that does it for now. Let's go on to The Date Object: JS Clock.
||By: John Pollock||