Detect Internet ExplorerTag(s): Varia

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

<h1> Internet Explorer</h1>
<![endif]-->


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

<!--> <![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.





If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2012
[ home ]