Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Check if user is using IE

Check if user is using IE
javascript jquery internet-explorer browser-detection
I am calling a function like the one below by click on divs with a certain class.

Is there a way I can check when starting the function if a user is using Internet Explorer and abort / cancel it if they are using other browsers so that it only runs for IE users ? The users here would all be on IE8 or higher versions so I would not need to cover IE7 and lower versions.

If I could tell which browser they are using that would be great but is not required.
Example function
$('.myClass').on('click', function(event)
{
// my function
});
by

2 Answers

akshay1995

function msieversion() {

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

if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) // If Internet Explorer, return version number
{
alert(parseInt(ua.substring(msie + 5, ua.indexOf(".", msie))));
}
else // If another browser, return 0
{
alert('otherbrowser');
}

return false;
}
sandhya6gczb
t's several years later, and the Edge browser now uses Chromium as its rendering engine.
Checking for IE 11 is still a thing, sadly.

Here is a more straightforward approach, as ancient versions of IE should be gone.

if (window.document.documentMode) {
// Do IE stuff
}

Login / Signup to Answer the Question.