PSD to HTML conversion PSD to HTML conversion PSD2HTML.com with over 300 professionals takes the designs to HTML and beyond

Code Snippet

Home » Code Snippets » JavaScript » Detect Internet Explorer

Detect Internet Explorer

<script type="text/javascript">

if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (ieversion>=8)
  document.write("You're using IE8 or above")
 else if (ieversion>=7)
  document.write("You're using IE7.x")
 else if (ieversion>=6)
  document.write("You're using IE6.x")
 else if (ieversion>=5)
  document.write("You're using IE5.x")
}
else
 document.write("n/a")

</script>

Reference

Subscribe to The Thread

  1. Luca says:

    Sniffing user agent is not a “safe” solution.
    I prefer the Dean Edwards one:


    var isMSIE = /*@cc_on!@*/false;

    (More here: http://dean.edwards.name/weblog/2007/03/sniff/ )

  2. CaTaHaC says:

    Or simply use what has already been built and not rewrite it:
    if ($.browser.ie) { … }

Speak, my friend

At this moment, you have an awesome opportunity* to be the person your mother always wanted you to be: kind, helpful, and smart. Do that, and we'll give you a big ol' gold star for the day (literally).

Posting tips:
  • You can use basic HTML
  • When posting code, please turn all
    < characters into &lt;
  • If the code is multi-line, use
    <pre><code></code></pre>
Thank you,
~ The Management ~