| home / experts / diner / scriptsrc |
|

If we try to load an external file with the script developed on the previous page, Explorer 4 (both 4.01 and 4.5) will give us this error:

What Explorer 4 Macintosh objects to is the dynamically written closing script tag (</SCRIPT>). It sees it as a literal closing tag, complementary to the first <SCRIPT> tag. In other words, it parses the tags and script as if they were written like this:
<SCRIPT LANGUAGE="JavaScript1.2">
<!--
document.write("<SCRIPT LANGUAGE='JavaScript1.2' SRC='myDHTMLSource.js'>
</SCRIPT>
. . .
The document.write() method, above, attempts to write an unterminated string, so the error is generated.
Explorer 4 for the Macintosh must be made aware that the dynamically written "</SCRIPT>" is not to be taken literally, but be included as part of the string to be written to the page.
We simply escape the forward slash (/), with a backslash (\), so that IE4Mac recognizes it as part of the string:
<SCRIPT LANGUAGE="JavaScript1.2">
<!--
document.write("<SCRIPT LANGUAGE='JavaScript1.2' SRC='myDHTMLSource.js'><\/SCRIPT>");
//-->
</SCRIPT>
Now, all version 4, DHTML-enabled, browsers will load and execute the external script.
Well, they will, but it won't be HTML 4 compatible. Since more and more webmasters insist on standards-compliance, we should make one addition to the tags.
Produced by Peter Belesis and
All Rights Reserved. Legal Notices.
Created: Nov 2, 1999
Revised: Nov 2, 1999
URL: http://www.webreference.com/dhtml/diner/scriptsrc/scriptsrc3.html