Last Updated: February 25, 2016
·
1.858K
· bradrice

Target IE with javascript

Since checking for browser is deprecated checking for IE documentMode can be helpful if you are trying to support lower versions or for a user who has mistakenly set their browser to compatibility mode.

<!--[if IE]> 
<script>
if(document.documentMode)
{
  //target IE browsers
  document.write(document.documentMode);
  //document.documentMode contains and integer of the IE version the page is rendering at
}
</script>
<![endif]-->

3 Responses
Add your response

@bradrice Do you know which IE versions do support this property and how does it work with IE Mobile?

over 1 year ago ·

I'm not sure about IE Mobile. I've tested this in IE8 with compatibility view set and not set and it reports correctly for those. If compatibility view is set, then it reports 7. If it is not, it reports 8. You can use this for multiple reasons. One would be to redirect people to a basic page if they are using 7 or below.

over 1 year ago ·

Thank you very much, that's a really great tip @bradrice!

over 1 year ago ·