jquery 1.4 的特征检测

发布于 2024-08-21 17:03:10 字数 70 浏览 3 评论 0原文

我如何通过使用功能检测来检测浏览器是否是 firefox、ie(但不是 ie6)、opera、chrome 或 safari?

How would I go about doing a detect to see if the browser is either firefox, ie (but not ie6), opera, chrome or safari by using feature detection?

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

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

发布评论

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

评论(3

浅忆 2024-08-28 17:03:10

功能检测不应告诉您用户正在使用哪种浏览器。它的目的是告诉您浏览器是否可以处理您需要做的事情。

例如,如果您需要支持 ActiveX,您可能会检查

if(ActiveXObject) { ... }

这比检查浏览器是否是 IE 更好,因为其他一些浏览器(当前或未来)也可能支持 ActiveX。

一个更有用的示例可能是遍历节点列表时的文本节点检查。

if (!el.tagName || el.tagName != expectedTagName)
    el = el.nextSibling;    // skip the text node

Feature detection is not supposed to tell you which browser the user is using. It is meant to tell you if the browser can handle what you need to do.

So for instance, if you need to support ActiveX, you might check

if(ActiveXObject) { ... }

This is better than checking if the browser is IE because some other browser (current or future) might support ActiveX too.

A more useful example may be text node checking when traversing a node list.

if (!el.tagName || el.tagName != expectedTagName)
    el = el.nextSibling;    // skip the text node
尐偏执 2024-08-28 17:03:10

对于 Safari:我将采用服务器端路线,即使用 Chris Schuld 的 Browser.php;除了 http 用户代理之外,关于 Safari 功能检测的文档很少。

For Safari: I'm going the server side route, ie using Chris Schuld's Browser.php; apart from the http user agent there's very little documentation about Safari feature detection.

想你只要分分秒秒 2024-08-28 17:03:10

我正在寻找答案,想也许有人已经解决了我的问题。
像许多人一样,我最终编写了自己的:

    try {
        if (ActiveXObject != undefined) {
            alert("we have activex");
    }
    }
    catch (err)
    {
        alert(err.message);
    }

当然,您会想要自定义您的实现。我的例子只是展示了基本逻辑。
哈!

I was searching for an answer, thinking perhaps someone had solved my issue.
Like many, I ended up writing my own:

    try {
        if (ActiveXObject != undefined) {
            alert("we have activex");
    }
    }
    catch (err)
    {
        alert(err.message);
    }

You will, of course, want to customize your implementation. My example just shows the base logic.
HTH!

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