ASP 101 - Active Server Pages 101 - Web05
The Place ASP Developers Go!

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash



 Top ASP 101 Stories Top ASP 101 Stories
Getting Scripts to Run on a Schedule
The Top 10 ASP Links @ Microsoft.com
What is Adovbs.inc and Why Do I Need It?

QUICK TIP:
Be Sure To Randomize Your Random Numbers
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates


Quick Tips


Nested Script Tag Weirdness

Ever get the feeling that software companies add bugs just to mess with you? This is one of those types of things. I've known about it for a while, but one of our visitors just reminded me of it and I thought I'd take this opportunity to share the weirdness.

This script works perfectly:

<%
Response.Write("<script language=""javascript"">" & vbCrLf)
Response.Write("<!--" & vbCrLf)
Response.Write("alert('The time at the server is: ")
Response.Write(Time() & "');" & vbCrLf)
Response.Write("//-->" & vbCrLf)
Response.Write("</script>" & vbCrLf)
%>

This one (the same script only in script tags instead of <% %>) doesn't work:

<script language="VBScript" runat="server">
Response.Write("<script language=""javascript"">" & vbCrLf)
Response.Write("<!--" & vbCrLf)
Response.Write("alert('The time at the server is: ")
Response.Write(Time() & "');" & vbCrLf)
Response.Write("//-->" & vbCrLf)
Response.Write("</script>" & vbCrLf)
</script>

It throws an error complaining about nested script tags. The tag can be inside a string or even in a comment... it won't work either way! Okay... easy fix... I'll split the script tags so the compiler doesn't recognize them:

<script language="VBScript" runat="server">
Response.Write("<scr" & "ipt language=""javascript"">" & vbCrLf)
Response.Write("<!--" & vbCrLf)
Response.Write("alert('The time at the server is: ")
Response.Write(Time() & "');" & vbCrLf)
Response.Write("//-->" & vbCrLf)
Response.Write("</scr" & "ipt>" & vbCrLf)
</script>

Wouldn't you think that would take care of it? Well it doesn't... now it somehow decides that it's going to interpret the client side comment before the asp code and sends any ASP code(!) between the comment tags to the browser as text! That's right it sends your ASP source code to the client because it saw a client side HTML comment tag! Don't ask me why... I don't know and I don't want to know!

This one works:

<script language="VBScript" runat="server">
Response.Write("<scr" & "ipt language=""javascript"">" & vbCrLf)
Response.Write("<!-" & "-" & vbCrLf)
Response.Write("alert('The time at the server is: ")
Response.Write(Time() & "');" & vbCrLf)
Response.Write("//-" & "->" & vbCrLf)
Response.Write("</scr" & "ipt>" & vbCrLf)
</script>

No wonder people never use the script tags... <% %> all the way!  ;)

 

Thanks to Claude Schrader for reminding me about this little quirk.


Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to: webmaster@asp101.com.


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers