How can I reference this Javascript externally?

There’s a nifty javascript applet on this page that I’d like to add to my site (click “View Source” to see the scropt):

Everything works great, except I need to paste the entire Javascript in the “Head” of every page. Is there a way for me to place the script in its only .js file and reference it that way?



Stick the code in a file called “rolloverscript.js” (or whatever you want). Put that file in the same directory with all your HTML files. Then stick this in the HEAD of your HTML files:

<script language='JavaScript' src='rolloverscript.js'></script>

Is that what you meant? Or did I misunderstand the question?

No, you understood it just fine. The only problem is that when I try that, the actual commands that draw upon that script (in the table containing the circles that enlarge) don’t seem to know where to draw it from, if that makes sense.

In short, the script doesn’t work when I try that.

It depends on where the file is located on the server, in relation to the pages it’s referenced in. If it is located in the root directory of your website, try

<script language='JavaScript' src='/rolloverscript.js'></script>

If it is located in a directory called ‘jscript’

<script language='JavaScript' src='/jscript/rolloverscript.js'></script>

Thanks, but I made sure the url is correct, yet it still doesn’t work for some reason. Could it be because the table where the effect is used doesn’t appear to refer to the javascript by name?

Edit: Also, do I need the “<script language=JavaScript>” and "</Script> in the .js file itself?

Nevermind, I’m an idiot. I got it working (the file had two .js extensions by mistake. Thanks everyone!