Articles | IE 3.02 and SRC
files | back
Introduction
Since the introduction of Internet Explorer version
3.02 (and possibly 3.01) the SRC attribute of the <SCRIPT>
tag has become supported (in a limited sense).
The full syntax of the <SCRIPT> tag
according to the Netscape JavaScript 3.0 Guide is:
<SCRIPT LANGUAGE="JavaScriptVersion">
JavaScript statements...
</SCRIPT>
|
or
<SCRIPT SRC="SourceFileName.js">
JavaScript statements...
</SCRIPT>
|
Where the JavaScript statements between the <SCRIPT>
and </SCRIPT> tags are ignored unless the SRC file is not found.
JavaScript Versions
The JavaScript Versions currently recognized are:
- <SCRIPT LANGUAGE="JavaScript">
specifies JavaScript for Navigator 2.0 or JScript for Internet Explorer 3.0.
- <SCRIPT
LANGUAGE="JavaScript1.1"> specifies JavaScript for
Navigator 3.0 and is ignored by Navigator 2.0 and Internet Explorer 3.0.
- <SCRIPT
LANGUAGE="JavaScript1.2"> specifies JavaScript for
Navigator 4.0 and Internet Explorer 4.0 and is ignored by Navigator 2.0 and
3.0 and Internet Explorer 3.0.
- <SCRIPT LANGUAGE="VBScript">
specifies Visual Basic Script for Internet Explorer 3.0 and is ignored by
Navigator 2.0 and 3.0.
However, when using the SRC attribute the LANGUAGE
attribute is ignored in Netscape Navigator.
*.js Source Files
As explained in two earlier articles Source
Files and Highlighting Images (#2) SRC
files should contain only JavaScript statements, or functions which can be
accessed by the main document as though they were part of that document.
With Internet Explorer version 3.02 there are
limitations, for example:
- the statement document.write('Here I am');
does not actually write the text 'Here I am' to the current
document. However, the statement alert('Here I am); would actually
display the alert message 'Here I am',
- the statement document.write('>'); will
actually cause Internet Explorer 3.02 to crash.
One ideal use of SRC files in Internet
Explorer 3.02 would be the storage of JavaScript functions that returned text
which the main document would then display. For example:
Within the test.htm document load the test.js
file and write the output from the format_text() function to the
document:
<HTML>
<BODY>
<SCRIPT SRC='test.js'></SCRIPT>
<SCRIPT>
document.write(format_text('test'));
</SCRIPT>
</BODY>
</HTML>
|
Within the test.js file define the format_text()
function (note the absence of any HTML):
function format_text(string) {
return 'This is a '+string;
}
|
If people still carry on using Internet Explorer
version 3.0, despite the implicit security problems, then with the previous
example, the error message 'format_text' is undefined would be
returned.
Working Example
The following extended example, uses the okay
variable which is set to true within the SRC file, which is then
subsequently tested before using any of the functions within the SRC
file:
Within the test.htm document set the okay
variable to false and only use the format_text() function if okay
is true:
<HTML>
<BODY>
<SCRIPT>
var okay = false;
</SCRIPT>
<SCRIPT SRC='test.js'></SCRIPT>
<SCRIPT>
if (okay) document.write(format_text('test'));
</SCRIPT>
</BODY>
</HTML>
|
Within the test.js file set the okay
variable to true:
okay = true;
function format_text(string) {
return 'This is a '+string;
}
|
If the SRC file does not load then the okay
variable will remain set to false, and the format_text() function will
not subsequently be invoked.
Why not try out
this example!
With Internet Explorer version 3.02, if the LANGUAGE
attribute is defined then, unlike Netscape Navigator, it is not ignored.
Therefore it is possible to exclude Internet Explorer version 3.02 from using a
particular SRC file by coding the <SCRIPT> tag as
follows:
<SCRIPT LANGUAGE="JavaScript1.1" SRC="FileIgnoredByIE3.02.js"></SCRIPT>
|
Obviously, these are contrived examples, that are not
worth the effort involved, but it could be expanded to define whole libraries of
JavaScript functions that once loaded in the browsers cache would be instantly
available to all your HTML files.
Articles | IE 3.02 and SRC
files | back
|