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

查看:37
本文介绍了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 在样式中不支持 opacity 的浏览器中为 false(尽管 IE 7-8 处理透明 PNG 文件,所以这仍然不是'不理想,取决于您的追求……我个人认为您会给 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天全站免登陆