Share this page 

Detect Internet ExplorerTag(s): Varia


<html>
<body>
<!--[if IE]>

<h6>** Internet Explorer **</h6>
<![endif]-->


<!--[if !IE]> <-->
<h6>** NOT  Internet Explorer **</h6>

<!--> <![endif]-->

</body>
</html>
With the browser used to view this page, the result is :

** NOT Internet Explorer **

This technique is using conditional comments, They only work in Internet Explorer on Windows, and are thus excellently suited to give special instructions meant only for Internet Explorer on Windows. All other browsers will see them as normal comments and will ignore them entirely.

It's possible to detect the IE version too.

<script>
    var isIE = false;
    var version = -1;
</script>
<!--[if IE 6]>
    <script>
        isIE = true;
        version = 6
    </script>
<![endif]-->
<!--[if IE 7]>
    <script>
        isIE = true;
        version = 7
    </script>
<![endif]-->

With the browser used to view this page, the result is :<br>
<script>
   document.write("IE : " + isIE + "<br>");
   document.write("version : " + version + "<br>");
</script>
With the browser used to view this page, the result is :

See also this HowTo.