开发者

Feature detection for jquery 1.4

开发者 https://www.devze.com 2022-12-19 13:32 出处:网络
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?Feature detection is not supposed to te

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?


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


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.


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消