DHTML Lab - dhtmlab.com - Hierarchical Menus Ver. 3 - Addendum VIIIa (v3.08a) | 3 | WebReference

DHTML Lab - dhtmlab.com - Hierarchical Menus Ver. 3 - Addendum VIIIa (v3.08a) | 3

Logo

Hierarchical Menus Ver. 3 - Addendum VIIIa (v3.08a)
Active Server Pages


The ASP problem has been previously addressed in the Hierarchical Menus FAQ, as FAQ #2.

The Problem

When loading a page with the HM script, ASP display 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">
<!--
if (isMenu) {
document.write("<SCRIPT LANGUAGE='JavaScript1.2' SRC='hierArrays.js' TYPE='text/javascript'><\/SCRIPT>");
document.write("<SCRIPT LANGUAGE='JavaScript1.2' SRC='hierMenus.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="hierArrays.js" TYPE="text/javascript"></SCRIPT>
   <SCRIPT LANGUAGE="JavaScript1.2" SRC="hierMenus.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="hierArrays.js" TYPE="text/javascript"></SCRIPT>
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">
   <SCRIPT LANGUAGE="JavaScript1.2" SRC="hierMenus.js" TYPE="text/javascript"></SCRIPT>
</SCRIPT>

The Solution

The nested SCRIPT tag needs to be hidden from the ASP engine. This is easily 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">
<!--
if (isMenu) {
document.write("<SCR" + "IPT LANGUAGE='JavaScript1.2' SRC='hierArrays.js' TYPE='text/javascript'><\/SCR" + "IPT>");
}
//-->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">
<!--
if (isMenu) {
document.write("<SCR" + "IPT LANGUAGE='JavaScript1.2' SRC='hierMenus.js' TYPE='text/javascript'><\/SCR" + "IPT>");
}
//-->
</SCRIPT>

Pretty nasty stuff, but all is fair in love and browser compatibility. When you get the time, maybe you'll want to update your in-page scripts to this gruesome but quite compatible version.


Produced by Peter Belesis and

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

URL: http://www.webreference.com/dhtml/column21/addendum8a/col21addVIIIa3.html