Soo Rhee
Soo Rhee

Reputation: 19

Brower detection in JavaScript (Internet Explorer)

I am trying to detect internet explorer using ua.match, but this code is not working. Does anyone know why? (it works for other browers)

ua.match(/.*;MSIE (\.?\d+);.*/g)

Below is the code that works for Safari

ua.match(/.*Safari\/(\.?\d+).*/g)

Upvotes: 0

Views: 470

Answers (2)

Soo Rhee
Soo Rhee

Reputation: 19

from explorer ver 7 to 11, this one covers

if ( (navigator.appName == 'Netscape' && navigator.userAgent.search('Trident') != -1) || (ua.indexOf("msie") != -1) || (ua.indexOf('msie ')))

Upvotes: 0

Emre Kabaoglu
Emre Kabaoglu

Reputation: 13146

IE 11 doesn't provide MSIE, it provides Trident. You should consider it;

var ua = navigator.userAgent;
if(ua.indexOf("MSIE ") > -1 || ua.indexOf("Trident") > -1)
{
    console.log("IE");
}

Upvotes: 2

Related Questions