English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

If I have a Javascript code, where do I need to put it, for it to do its function.
Do I need to put it into notepad and save it as a speific file extension or what?

2007-08-24 00:44:14 · 3 answers · asked by Mat C 1 in Computers & Internet Programming & Design

3 answers

You may load an external JavaScript file (commonly with the “.js” file extension):



You would change “/foo/bar.js" to the location of your file.


Alternatively, you can include the code inline:




The tags anywhere on the page. Normally people put it in the header just so its in one common spot. If you are using a function on window load, and it refers to DOM, make sure you put it below what you are referring to, or in some browsers you will get an error.

You do not need to put it in its own seperate file, .js files are commonly used for javascript that will be used on all pages. If you are using a script thats page specific put it in the header or somewhere you can find it easily. Make it your norm.

2007-08-24 08:34:33 · answer #2 · answered by Big D 4 · 0 0

JavaScript is usually written using Notepad and saved in a file with and extension of .js
The file is also usually kept in a folder named scripts

Some javaScript can also be directly included into the html document using the