View Full Version : How To Create an External JS File?

05-20-2005, 05:22 PM

Can anyone give instructions, or know where I can find instructions, on creating an external java script file? Plain, precise, non-techy language would be best in my case, but any help at all will be appreciated.


05-20-2005, 06:13 PM
Do you mean write an external javascript from scratch or adapt an existing internal one to be used as an external one? From scratch is easy,

alert('Done!');Simply save the above code to a file and name it 'alertdone.js'
Add this code to the head of your html page:

<script src="alertdone.js" type="text/javascript"></script>Adapting an internal script is similar but can get tricky depending upon the script. Many can be adapted simply by removing the '<script>' and '</script>' tags from the code, saving that code to a file and giving that file a name say, 'myscript.js', then putting this in the head or body (depending upon where the script was originally meant to go) of your page:

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

05-20-2005, 08:55 PM
Many can be adapted simply by removing the '<script>' and '</script>' tags from the code [...]It should also be noted that SGML comments (<!-- ... -->), should be removed. So, given:

<script type="text/javascript">
<!-- Hide from browsers

/* Script content */

// -->

/* Script content */should be saved. The SGML comments shouldn't be present anyway, but many old scripts haven't been updated to omit them.