In general, the practice of User Agent sniffing and conditional compilation/comments are best avoided. It is far better to use feature detection, graceful degradation , and progressive enhancement instead. However, for the few edge cases where it is more convenient for the developer to detect the browser version, you can use the following code snippets:
This if
statement will only execute on IE 10
// IF THE BROWSER IS INTERNET EXPLORER 10
if (navigator.appVersion.indexOf("MSIE 10") !== -1)
{
window.alert('This is IE 10');
}
This if
statement will only execute on IE 11
// IF THE BROWSER IS INTERNET EXPLORER 11
var UAString = navigator.userAgent;
if (UAString.indexOf("Trident") !== -1 && UAString.indexOf("rv:11") !== -1)
{
window.alert('This is IE 11');
}
http://jsfiddle.net/Qz97n/