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
});
@SpiderCode's solution does not work with IE 11. Here is the best solution that I used henceforth in my code where I need browser detection for particular feature.
IE11 no longer reports as MSIE, according to this list of changes, it's intentional to avoid mis-detection.
What you can do if you really want to know it's IE is to detect the Trident/ string in the user agent if navigator.appName returns Netscape, something like (the untested);
Thanks to this answer
You can use
$.browser
to get name, vendor and version information.See http://api.jquery.com/jQuery.browser/
This is how the Angularjs team is doing it (v 1.6.5):
Then there are several lines of code scattered throughout using it as a number such as
and
As of Internet Explorer 12+ (aka Edge), the User Agent String has changed, once again.
Sample usage:
Default string of IE 10:
Default string of IE 11:
Default string of IE 12 (aka Edge):
Default string of Edge 13 (thx @DrCord):
Default string of Edge 14:
Default string of Edge 15:
Default string of Edge 16:
Default string of Edge 17:
Default string of Edge 18 (Insider preview):
Test at CodePen:
http://codepen.io/gapcode/pen/vEJNZN
This only work below IE 11 version.
console.log("version number",ie_version);
Using modernizr