jQuery浏览器检测? [英] jQuery browser detection?

查看:101
本文介绍了jQuery浏览器检测?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种很好的方法来检测用户的浏览器是否是使用jQuery的Internet Explorer?

Is there a good way to detect if the user's browser is Internet Explorer using jQuery?

我有使用IE浏览器的PNG图形问题,并希望将它们换成仅当用户使用IE查看网站时才会使用GIF。

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.

推荐答案

可以使用 $。browser ,是的,但这很糟糕使用浏览器检测的想法:

You can using $.browser, yes, but it's a bad idea to use browser detection:

if($.browser.msie) { /* IE */ }

例如,一个更好的选择是 $ .support 这是功能检测,如下所示:

A better option for instance would be $.support which is feature detection, like this:

if(!$.support.opacity) { /* IE 6-8 */ }

$ .support.opacity 在不支持不透明度的浏览器中为false (虽然IE 7-8处理透明的PNG文件,所以这仍然不是id eal,取决于你所追求的......我个人认为你会给IE 7/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).

你应该做什么真的做的是目标IE6,其中支持透明PNG(没有alpha过滤器),如下所示:

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]-->

这篇关于jQuery浏览器检测?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆