DHTML Lab - dhtmlab.com - Dynamic Headline Fader, Version 3.0 | 4 | WebReference

DHTML Lab - dhtmlab.com - Dynamic Headline Fader, Version 3.0 | 4

Logo

Dynamic Headline Fader, Version 3.0
Loading the external scripts with ASP


The Problem

When loading an Active Server Page (ASP) page with the Fader script, the ASP interpreter displays an error message regarding "improperly nested SCRIPT tags."

Once again, the problem is caused by our conditional script-loading statements, which were:

<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">
<!--
document.write("<SCRIPT LANGUAGE='JavaScript1.2' SRC='news.js' TYPE='text/javascript'><\/SCRIPT>");
document.write("<SCRIPT LANGUAGE='JavaScript1.2' SRC='fader.js' TYPE='text/javascript'><\/SCRIPT>");
//-->
</SCRIPT>

When ASP build the page, they render the statements literally, creating illegal HTML:

<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">
   <SCRIPT LANGUAGE="JavaScript1.2" SRC="news.js" TYPE="text/javascript"></SCRIPT>
   <SCRIPT LANGUAGE="JavaScript1.2" SRC="fader.js" TYPE="text/javascript"></SCRIPT>
</SCRIPT>

With our new, old-Navigator-compatible version, ASP would try to render:

<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">
   <SCRIPT LANGUAGE="JavaScript1.2" SRC="news.js" TYPE="text/javascript"></SCRIPT>
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">
   <SCRIPT LANGUAGE="JavaScript1.2" SRC="fader.js" TYPE="text/javascript"></SCRIPT>
</SCRIPT>

The Solution

The nested SCRIPT tag needs to be hidden from the ASP engine. This is accomplished by breaking the document.write() strings into 3 smaller strings, so that "SCRIPT" is never encountered as a complete word:

<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">
<!--
document.write("<SCR" + "IPT LANGUAGE='JavaScript1.2' SRC='news.js' TYPE='text/javascript'><\/SCR" + "IPT>");
//-->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">
<!--
document.write("<SCR" + "IPT LANGUAGE='JavaScript1.2' SRC='fader.js' TYPE='text/javascript'><\/SCR" + "IPT>");
//-->
</SCRIPT>

Done, with Fader Version 3.0. If you've lost track of all the browser versions our script is now compatible with, check out the compatibility table on the next page. After that, we'll repeat the complete code.


Produced by Peter Belesis and

All Rights Reserved. Legal Notices.
Created: Nov 30, 1999
Revised: Nov 30, 1999

URL: http://www.webreference.com/dhtml/column27/fade3asp.html