NOTE : JavaScript is currently supported by the Netscape Navigator (version 2 and above) and Internet Explorer (version 3.0 and above). Recently, Netscape presented Javascript 1.1 to the ECMA, where it has evolved into ECMAScript (or rather ECMA-262), "A general purpose, cross-platform programming language". Netscape then proceeded to make extensions to Javascript, which became Javascript 1.2 as supported in the Navigator component of Netscape Communicator. Microsoft's JScript (v3.0 of which ships with Internet Explorer 4.0) is currently the only full implementation of ECMAScript. All Javascript 1.2 extensions are also supported by Internet Explorer 4.0 through its enhanced scripting object model.
For more information on JavaScript, visit http://home.netscape.com/ for Netscape's JavaScript information, or http://www.microsoft.com/jscript/ for Microsoft's 'JScript' JavaScript implementation, or the ECMA site for the official ECMAScript specification. The information provided here only details how to include JavaScript scripts within HTML documents, not how to author actual scripts. Such information is well beyond the scope of this reference.
NOTE : A Scripting Reference is now included in the HTMLib. This details various methods of invoking scripts, and a description of the object models of both browsers. Note that the Internet Explorer object model available through scripting languages covers every element, whereas the Netscape one doesn't.
A script is embedded in HTML within a <SCRIPT>
element.
<SCRIPT>...</SCRIPT>
The text of a script is inserted between <SCRIPT>
and its end element.
Attributes within the <SCRIPT>
element can be specified as follows:
<SCRIPT LANGUAGE="JavaScript">
. . .
</SCRIPT>
The LANGUAGE attribute is mandatory unless the SRC attribute is present and specifies the scripting language. NOTE : Use of the LANGUAGE
attribute is important now that Internet Explorer supports JavaScript. In order for the Internet Explorer to know it is to process the script as JavaScript, it needs to be told that it is JavaScript. See below for JavaScript versioning information.
The SRC
attribute is optional and, if given, specifies a URL that loads the text of a script.
<SCRIPT LANGUAGE="language" SRC="url">
Both attributes may be present.
NOTE : For Netscape to be able to properly use external JavaScript files, the server on which the files are to reside must have the MIME type application/x-javascript
mapped into its list of MIME types (with a suitable extension mapped to it - Netscape recommend ".js"
) for Netscape to properly respond to the script when it is loaded. Internet Explorer is more relaxed about the extension of the external script document, though it will still need to be registered with the MIME types on the web server, to ensure proper functioning.
Scripts should be placed inside comment fields to ensure that the script is not displayed when the page's HTML is viewed with a browser unaware of the <SCRIPT>
element. The entire script is encased by HTML comment elements:
<SCRIPT LANGUAGE="language" SRC="url">
<!-- Begin to hide script contents from old browsers.
. . . Script functions/routines go here
End the hiding here.-->
</SCRIPT>
Note that in Netscape, the final HTML comment must be 'commented' out using a JavaScript comment '//' otherwise an error occurs. For more information about scripts, the JavaScript language and some examples, see http://home.netscape.com/. Also visit http://www.microsoft.com/, especially http://www.microsoft.com/jscript - the Microsoft JScript (Microsoft's JavaScript implementation) Web site.
JavaScript version control
There are various versions of JavaScript supported by both Netscape and Internet Explorer. Because the various versions of JavaScript support subtly different object models and function capabilities, you can version out various browsers that do not support the scripting capabilities you've authored. The support breaks down as follows :
Version | LANGUAGE value |
Internet Explorer | Netscape |
---|---|---|---|
1.0 | Javascript | From version 3.0 |
From version 2.0 onwards |
1.1 | Javascript1.1 | IEx 3.0x doesn't support all functionality. IEx 4.0+ does. |
From version 3.0 onwards |
1.2 | JavaScript1.2 | IEx 3.0x throws ''function' not defined' error. Is supported by IEx 4.0+ | Version 4.0 only |
So, if you're authoring using JavaScript v1.1 (as supported by Netscape 3.0 and above, for example, if you're manipulating the image object), then use LANGUAGE="Javascript1.1"
in the <SCRIPT>
element. The code functions will then be ignored by Netscape browsers older than version 3.0. Note that Internet Explorer understands both 'Javascript' and 'Javascript1.1' as values of the LANGUAGE
attribute, but doesn't currently support certain functionality in Javascript 1.1.
By using versioning in the LANGUAGE
attribute, you can author alternative scripting functions for the various different versions of Netscape within the same document, allowing great flexibility.
Example
Here is a quick (and very simple) example, where pressing the button provides a greeting according to the present time of day on your system.
© 1995-1998, Stephen Le Hunte
file: /Techref/language/html/ib/Scripting_Reference/javascr.htm, 9KB, , updated: 2004/3/1 15:47, local time: 2024/12/26 22:35,
18.119.166.141:LOG IN
|
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://linistepper.com/Techref/language/html/ib/Scripting_Reference/javascr.htm"> Javascript</A> |
Did you find what you needed? |