Javascript Detect IE Browser

  • 0


var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");

if (msie > 0){
  // Do Something
}



UPDATE FOR IE 11

var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");

if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)){
  // Do Something
}



DETECT IE VERSION
 
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
if (msie > 0){
   var version = parseInt(ua.substring (msie+5, ua.indexOf(".", msie)))
   if(version <= 9) {
     // Do Something 
   }
}


No comments:

Post a Comment