Is there a good way to detect if the user's browser is Internet Explorer using jQuery?
I have an issue with PNG graphics using IE and want to swap them for GIF's only if the user is viewing the site with IE.
Specific feature detection checks if a specific feature is available, instead of developing against a specific browser. This way, developers can write their code for two cases: the browser does support said feature, or the browser does not support said feature.
We can access various properties of this object 'Modernizr' for feature detection using “Modernizr. featureName”. For example, Modernizr. video will return “true” if the browser supports the video element, and false if the browser doesn't.
To detect user browser information we use the navigator. userAgent property. And then we match with the browser name to identify the user browser. Now call this JS function on page load, and this will display the user browser name on page load.
You can using $.browser
, yes, but it's a bad idea to use browser detection:
if($.browser.msie) { /* IE */ }
A better option for instance would be $.support
which is feature detection, like this:
if(!$.support.opacity) { /* IE 6-8 */ }
$.support.opacity
is false in browsers that don't support opacity
in styling (though IE 7-8 handle transparent PNGs file, so this still isn't ideal, depending on what you're after...personally I think you'd be giving IE 7/8 users a sub-optimal experience).
What you should really do is target IE6 which doesn't support transparent PNGs (without an alpha filter), like this:
<!--[if IE 6]>
<link rel="stylesheet" type="text/css" href="IE6ImageStyles.css">
<![endif]-->
Yes, you can, but they prefer you to use jQuery.support
: http://api.jquery.com/jQuery.support/.
In this case, use jQuery.support.opacity
.
Edit: assuming this is about opacity, of course.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With