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
});
Or this really short version, returns true if the browsers is Internet Explorer:
I know this is an old question, but in case anyone comes across it again and has issues with detecting IE11, here is a working solution for all current versions of IE.
You should see the result in console, please use chrome Inspect.
Update to SpiderCode's answer to fix issues where the string 'MSIE' returns -1 but it matches 'Trident'. It used to return NAN, but now returns 11 for that version of IE.
You can dectect all Internet Explorer (Last Version Tested 12).
See here https://jsfiddle.net/v7npeLwe/
I think it will help you Here