Search code examples
javascripthtmlconditional-commentshtml5shiv

Would this conditional statement work in an HTML page?


I want to only load the html5shiv.js file if the web browser is less than IE 9.

The code I have is

<doctype html>
 <html>
 <head>
  <!--[if lt IE 9]
      <script type="text/javascript" src="html5shiv.js"></script>
  -->
 </head>
 <!-- ... -->
</html>

When I test to see if this works or not (I do this by changing the Browser Mode option to a version lower than IE 9 in Developer Tools - I'm not clear as to whether this works or not.

Does this work for you - or is the code atleast right?


Solution

  • You may be missing a chevron at the end of the first line and the closing tag:

    <!--[if lt IE 9]>
     <script type="text/javascript" src="html5shiv.js"></script>
    <![endif]-->