JavaScript EditorBest javascript editor debugger     Ajax website 



Main Page

Previous Page
Next Page

Adding an "Automatic" Script

There are two kinds of scriptsthose that are executed without the visitor having to do anything and those that react to something the visitor has done. The first group might be called "automatic scripts" and are executed by the browser when the page is loaded. You can have as many automatic scripts as you like on a page. They will run in the order they appear. (The second group, "triggered scripts", is discussed on page 314.)

To add an automatic script:

1.
In your (X)HTML document, type <script.

2.
Type type="text/language-name", where language-name identifies the scripting language you're using: javascript, vbscript, etc.

3.
Type language="script", where script is the name of the scripting language you'll be using: JavaScript, VBScript, etc.

4.
Type >.

5.
Type the content of the script.

6.
Type </script>.

Figure 19.1. A script may appear anywhere in your (X)HTML document. However, where it appears determines when it will be executed.


Figure 19.2. This simple JavaScript script is output to the browser window itself. Other scripts send their results elsewhere.


Tips

  • The language attribute is deprecated and thus only valid in (X)HTML transitional (see page 40). Nevertheless it is often used to maintain compatibility with older browsers.

  • The location of the script on the (X)HTML page determines when it will load. Scripts are loaded in the order in which they appear in the (X)HTML file. If you want your script to load before anything else, be sure to place it in the head section.

  • For hiding scripts in XHTML pages from XML parsers, see page 319.



Previous Page
Next Page


JavaScript EditorBest javascript editor debugger     Ajax website