[Javascript] Beginner's question

Paul Novitski paul at novitskisoftware.com
Sat Jan 28 01:41:48 CST 2006


At 11:22 PM 1/27/2006, Jonathan Gold wrote:
>My website uses some javascripts. In some cases I call a function 
>that is declared in the <head> element. In other cases I simply 
>insert the function at the place it comes in the mark-up. I think my 
>html or xhtml markup would be more readable if I placed the 
>javascript functions in a separate file and called them from the 
>xhtml file (in the same way that I can offload my style sheet and 
>simply refer to it from the webpage). I imagine there is a simple 
>way to do this. But I haven't imagined the syntax for such a thing. 
>:~) Is this a possibility; and how is it accomplished? Thanks much, 
>-- Jonathan Gold Berkeley, CA http://home.pacbell.net/jonnygee/


Absolutely, Jonathan:

<script type="text/javascript" src="myscript.js"></script>

where "myscript.js" is the filename of your script.  You can have as 
many of these script links as you need.

ref:
Local declaration of a scripting language
http://www.w3.org/TR/html4/interact/scripts.html#h-18.2.2.2

The HTML 4.01 specification is actually fascinating reading, well 
worth taking the time for.

You may know already that you can start a script (whether inline or 
externally linked) executing with:

         window.onload = functionName;

where functionName() is the function you want to execute first.

Have fun,
Paul 




More information about the Javascript mailing list