23 May 2013

How to detect IE10 through JavaScript

I was struggling to detect Internet Explorer 10 through JavaScript. 

Its pretty simple, right?

But its not easy if you change the browser mode or document through developer toolbar or if are running on compatible mode. Most of the solution out there on the internet stopped working for such special cases.

Finally I have found the solution to detect IE10 in all such cases:
- Quirks mode 
- Standards mode 
- Browser mode
- Document mode

<script>

var isIE10 = false;

/*@cc_on
if (/^10/.test(@_jscript_version)) {
isIE10 = true;
}
@*/
alert("Is my running on IE10? " + isIE10);

</script>

No comments: