Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<!--[If IE]> Not working

<html>
  <head>
    <!-- [If IE]><script>alert('IE!')</script><![endif] -->
  </head>
  <body>
    <p>
      Hello World
    </p>
  </body>
</html>

Is there something wrong with this, or do I need to add a DOCtype / meta heading to get it to work?

like image 935
joedborg Avatar asked Dec 21 '22 16:12

joedborg


2 Answers

This is just to clarify (since noone has really).

It's the space between <!-- and [If IE] aswell as the space after [endif] that breaks your code. It's not there in any of the answers that are previous to mine, therefor they work and yours do not.

Bad:

<!-- [If IE]> <![endif] --> 

Good:

<!--[If IE]> <![endif]--> 

<!DOCTYPE html> is a good practice, but not needed for this to work.

like image 110
Henrik Ammer Avatar answered Jan 07 '23 21:01

Henrik Ammer


This should work fine:

<!DOCTYPE HTML>
<html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>Untitled Document</title>
  <!--[if IE]><script src="global.js"></script><![endif]-->
</head>

<body>
  <p>Hello world</p>
</body>
</html>
like image 34
Oliver Tappin Avatar answered Jan 07 '23 23:01

Oliver Tappin