Why is my IE conditional comment throwing a compile error when not added via Response.Write?

I have a page with a conditional comment:

<%@ Page language="c#"  %>
<html>
  <head>
    <title>ASP.NET Application</title>
    <!--[if lt IE 8]><script type="text/javascript" src="scripts/json_parse.js"></script><![endif]-->
  </head>
  <body>
    test
  </body>
<html>

      

When I do this as described above, it throws a compilation error saying it expects a closing script tag. But the code below (which should end on the same page) works fine:

<%@ Page language="c#"  %>
<html>
  <head>
    <title>ASP.NET Application</title>
    <!--[if lt IE 8]>
    <% Response.Write( "<script type=\"text/javascript\" src=\"scripts/json_parse.js\"></script>" ); %>
    <![endif]-->
  </head>
  <body>
    test
  </body>
<html>

      

Why does this have an IE conditional issue? The script tag is inside a comment and is not "runat".

+3


source to share


1 answer


This is the case where you want conditional comments to appear in downstream browsers rather than hide in up-level browsers, so there is a slightly different syntax:

<![if lt IE 8]>
<script type="text/javascript" src="scripts/json_parse.js"></script>
<![endif]>

      



See this MSDN article for details .

+4


source







All Articles