一些非 IE 浏览器在 IE6 浏览器检测中显示为 true

发布于 2024-12-27 22:14:14 字数 1587 浏览 5 评论 0原文

所以我正在运行 jQuery 1.3.2(是的,它很旧,现在我无法升级)。

问题是我正在尝试放弃对我们内部站点的 IE6 支持并升级浏览器。我有这个检查

if($.browser.msie && $.browser.version=="6.0") {
    // do something...
}

,但在测试过程中(一些)Firefox 用户看到了 do some 条件,但不应该是这样。以下是我认为可能导致该问题的一些用户代理。

  • UserAgent:Mozilla/5.0(Windows NT 6.1;WOW64)AppleWebKit/535.7(KHTML,如 Gecko)Chrome/16.0.912.75 Safari/535.7
  • UserAgent:Mozilla/5.0(Windows;U;Windows NT 5.1;en-US;rv:1.9 .2.23) 壁虎/20110920 Firefox/3.6.23
  • UserAgent:Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.7(KHTML,如 Gecko) Chrome/16.0.912.75 Safari/535.7
  • UserAgent:Mozilla/5.0(Windows;U;Windows NT 6.1;en-US;版本:1.9.2.25) 壁虎/20111212 Firefox/3.6.25
  • UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12

我还需要更多 IE6 验证吗?

注意:最终用户没有安装任何附加组件。我以为像 IE-Tabs 这样的东西可能会导致问题,但事实并非如此

更新:

下面的所有回复都引导我到此,仍在测试,但看起来不错。关于如何改进它有什么想法吗?

var ie6 = $.browser.msie && parseInt($.browser.version) === 6 && typeof window['XMLHttpRequest'] !== "object";
if(typeof document.body.style.maxHeight === "undefined" && ie6) {
    alert('Your browser is IE6');
}

相关问题:

So I'm running jQuery 1.3.2 (yep it's old and right now I can't upgrade).

Problem is I'm trying to drop IE6 support for our internal site and upgrade the browser. I have this check

if($.browser.msie && $.browser.version=="6.0") {
    // do something...
}

But during testing (some) Firefox users are seeing the do something condition and should'nt be. Here are some of the User Agents that I think might be causing the issue.

  • UserAgent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7
  • UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.23) Gecko/20110920 Firefox/3.6.23
  • UserAgent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.75 Safari/535.7
  • UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.25) Gecko/20111212 Firefox/3.6.25
  • UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12

Is there more IE6 validation I need?

Note: The end user has no add-ons installed. I was thinking something like IE-Tabs could cause the issue but that's not the case

UPDATE:

All of the responses below lead me to this, still testing but it looks good. Any thoughs on how to improve it?

var ie6 = $.browser.msie && parseInt($.browser.version) === 6 && typeof window['XMLHttpRequest'] !== "object";
if(typeof document.body.style.maxHeight === "undefined" && ie6) {
    alert('Your browser is IE6');
}

Related questions:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

慕烟庭风 2025-01-03 22:14:14

不要使用浏览器检测。特征检测要好得多。如果您只想向 IE 6 用户显示消息或其他内容,我建议使用 条件注释< /a> 相反。

<!--[if IE 6]>
    <script type="text/javascript">
        // do something...
    </script>
<![endif]-->

Don't use browser detection. Feature detection is much nicer. And if you want to display a message or something to only IE 6 users, I would recommend using conditional comments instead.

<!--[if IE 6]>
    <script type="text/javascript">
        // do something...
    </script>
<![endif]-->
尘世孤行 2025-01-03 22:14:14

来自 jQuery 文档

<块引用>

$.browser 属性在 jQuery 1.3 中已弃用,其功能可能会在 jQuery 的未来版本中移至团队支持的插件中......

最好尽可能完全避免特定于浏览器的代码。 $.support 属性可用于检测对特定功能的支持,而不是依赖 $.browser。

或者,您可以使用:

  1. 使用 navigator 对象
  2. IE 条件语句编写自定义浏览器检测器,例如 < a href="http://reference.sitepoint.com/css/conditionalcomments" rel="nofollow">这个

From jQuery Documentation

The $.browser property is deprecated in jQuery 1.3, and its functionality may be moved to a team-supported plugin in a future release of jQuery....

It is always best to avoid browser-specific code entirely where possible. The $.support property is available for detection of support for particular features rather than relying on $.browser.

Altenatively you can use:

  1. Write custome browser detector using navigator object
  2. IE conditional statements, something like this
瑶笙 2025-01-03 22:14:14

感谢大家帮助我找到了我要找的东西,也许这可能对其他人有帮助

var ie6 = $.browser.msie && parseInt($.browser.version) === 6 && typeof window['XMLHttpRequest'] !== "object";
if(typeof document.body.style.maxHeight === "undefined" && ie6) {
    alert('Your browser is IE6');
}

Thanks all to helped me find what I was looking for, maybe this might help others

var ie6 = $.browser.msie && parseInt($.browser.version) === 6 && typeof window['XMLHttpRequest'] !== "object";
if(typeof document.body.style.maxHeight === "undefined" && ie6) {
    alert('Your browser is IE6');
}
向地狱狂奔 2025-01-03 22:14:14

如果你想让一行脚本找到IE6及以下版本并且不能使用条件注释:

if('\v'==='v' && !window.XMLHttpRequest) {
// 做某事...
}

if you want a line of script to find IE6 and below and you can't use conditional comments:

if('\v'==='v' && !window.XMLHttpRequest) {
// do something...
}

○闲身 2025-01-03 22:14:14

您想要做的事情是什么需要知道浏览器是否是 IE6?让我们消除它。

What is the thing you are trying to do that requires knowing if the browser is IE6? Let's eliminate that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文