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
});
You can use the navigator object to detect user-navigator, you don't need jquery for it
http://www.javascriptkit.com/javatutors/navigator.shtml
Method 01:
$.browser was deprecated in jQuery version 1.3 and removed in 1.9
Method 02:
Using Conditional Comments
Method 03:
Method 04:
Use JavaScript/Manual Detection
Reference Link
I've placed this code in the document ready function and it only triggers in internet explorer. Tested in Internet Explorer 11.
If you don't want to use the useragent, you could also just do this for checking if the browser is IE. The commented code actually runs in IE browsers and turns the "false" to "true".
i've used this
Yet another simple (yet human readable) function to detect if the browser is IE or not (ignoring Edge, which isn't bad at all):