Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org

Related items

A JavaScript Web-Ring

Source Files

Internet Explorer version 3.02 and SRC files

You are here: irt.org | Articles | JavaScript | Source | Internet Explorer version 3.02 and SRC files [ previous next ]

Published on: Tuesday 8th April 1997 By: Martin Webb

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:

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:

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.

Related items

A JavaScript Web-Ring

Source Files

Feedback on 'Internet Explorer version 3.02 and SRC files'

©2018 Martin Webb