|
|
This is an explanation of how to use the SCRIPT tag, and its attributes.
The end tag is required. All attributes except the Type are optional, though it is best to include both the language and type tag, so that the browser will know which language you are using. The HTML comment tags are not part of the specification, though they insure backwards compatibility. The comment end tag is preceded by a //, the JavaScript comment character. In the script data, you should be careful not to have any </ sequences, as this is formally supposed to end the script. You should escape them using the JavaScript escape character, the backslash, as follows: Document.Write "<P>This is a <B>paragraph.</B></P>"
would become This doesn't look nearly as nice, and is more work, but is necessary to comply with the HTML specification. Attributes:
The default scripting language can be set using a META tag in the HEAD, though this is not supported by current browsers. <META http-equiv="Content-Script-Type" content="text/javascript"> If you wish to have HTML content shown if the user's browser does not support scripting, you should use the NOSCRIPT tag.
NOSCRIPT is shown by script-aware browsers if scripting is disabled or a scripting language which it did not understand was used. NOSCRIPT supports all core attributes, international attributes, and events, though they are not needed. If you wish to make pages which are widely compatible and will work with the next generation of browsers without breaking, it is wise to use the Type AND Language attributes, while avoiding the Src, For and Event attributes. You should also provide alternate content. For example:
This will work with browsers which support the Type attribute, which will then ignore the Language attribute. Also, it will work with browsers which support the more common Language attribute, which will ignore the Type attribute. If they don't support either, they most probably don't support JavaScript. If you are willing to exclude users with IE3, you can use the Src attribute and store your scripts in external files. This can save you work, as you don't have to put it in each document, and allows you to keep the user from seeing the script if they open the HTML source. However, it excludes users with IE3, which could usually use JavaScript. The Title tag is available if you wish to provide more information about the script. Some information that you might use it for is the author's name and email address, and the purpose of the script. Most scripts, especially those containing shared functions, should be put in the HEAD of the document, so that they are loaded before the rest of the page. |
|