嗅探 Firefox 4 及更高版本的方法

发布于 2024-12-01 10:58:32 字数 584 浏览 2 评论 0原文

我正在编写一个 JavaScript 库,必须检查 Firefox 4 或更高版本。相信我,我需要这样做。

我计划使用以下嗅探代码:

if ('MozAppearance' in document.documentElement.style) {

    //We have Mozilla

    if (!!window.FormData) {

        //We have Firefox4+

    }
}

我对此感觉很好,因为(对我来说)似乎不太可能有人添加全局 FormData 方法。

假设我对与任何浏览器嗅探方法相关的常见风险感到满意,您能看出这有什么问题吗?

Firefox 中 window.FormData 的文档位于:

https://developer.mozilla.org/en /DOM/XMLHttpRequest/FormData

谢谢!

I am writing a JavaScript library that must check for Firefox 4 or higher. Trust me, I need to.

I'm planning to go with the following sniffing code:

if ('MozAppearance' in document.documentElement.style) {

    //We have Mozilla

    if (!!window.FormData) {

        //We have Firefox4+

    }
}

I feel ok about it because it seems rather unlikely (to me) that anyone will add a global FormData method.

Assuming I'm comfortable with the usual risks associated with any browser sniffing method, can you see any problems with this?

Documentation for window.FormData in Firefox is here:

https://developer.mozilla.org/en/DOM/XMLHttpRequest/FormData

Thanks!

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

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

发布评论

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

评论(3

花桑 2024-12-08 10:58:32

由您决定这是否是适合您的合理特征检测。如果您认为测试 FormData 是否存在就足够了;然后就这样吧。

您也可以“增加”您检查的功能。您还可以查找 window.URL,即 Firefox 4 中的新功能

if (!!window.FormData && !!window.URL) {

    //We have Firefox4+

}

因此,现在有人声明两者都具有的可能性甚至更低。如果您足够信任您的用户而不会更改他们,您也可以让用户代理参与其中。

That's up to you to decide if that is reasonable feature detection for you. If you believe that testing for the presence of FormData is enough; then go with that.

You can "increase" the features you check for as well. You can also look for window.URL, a new feature in Firefox 4 as well:

if (!!window.FormData && !!window.URL) {

    //We have Firefox4+

}

So now your odds that someone declared both are even lower. You could also get the user-agent involved as well if you trust your users enough to not change them.

秋千易 2024-12-08 10:58:32

window.history.pushState 是您可以检查的另一个。
我认为我们可以用 FF4+ 中出现但 FF3.x 中没有的功能来完成这一整天的工作。

window.history.pushState is another one you can check.
I think we could do this all day with features that appear in FF4+ but not FF3.x.

貪欢 2024-12-08 10:58:32

假设我对与任何相关的常见风险感到满意
浏览器嗅探方法,你能看出这个有什么问题吗?

一旦他们删除前缀,它就会崩溃。
所有 -moz- 属性 标记为过时的事实证明.
因此请记住,您必须使用 || 不断添加最新的 Mozilla 扩展。

Assuming I'm comfortable with the usual risks associated with any
browser sniffing method, can you see any problems with this?

It will break the moment they drop the prefix.
All the -moz- properties tagged obsolete attest of that fact.
So remember you will have to continually add recent Mozilla extensions using ||.

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