Ben
Ben

Reputation: 62464

Browser Detection via JS for Safari 5

How can I check if the user's current browser is Safari 5?

Update

We have a check on our site that displays a "Browser not supported" message if the user is using an older browser. Currently our error is showing up for the latest Safari and it shouldn't be.

Upvotes: 0

Views: 2201

Answers (2)

ob1
ob1

Reputation: 1721

If you indeed want to do this, you can check the User Agent along the same lines Ext uses to do it.

A snippet from Ext.js:

    ua = navigator.userAgent.toLowerCase(),
    check = function(r){
        return r.test(ua);
    },
    DOC = document,
    isStrict = DOC.compatMode == "CSS1Compat",
    isOpera = check(/opera/),
    isChrome = check(/\bchrome\b/),
    isWebKit = check(/webkit/),
    isSafari = !isChrome && check(/safari/),
    isSafari2 = isSafari && check(/applewebkit\/4/), // unique to Safari 2
    isSafari3 = isSafari && check(/version\/3/),
    isSafari4 = isSafari && check(/version\/4/),

I'm guessing for Safari 5 you could write a similar test where version would be 5, though I did not check what Safari 5's User Agent string looks like myself.

Upvotes: 3

Sarfraz
Sarfraz

Reputation: 382871

See:

jsBrowsersDetect

Or

Browser detect

But that is not a good practice, it is always best, however, to avoid browser specific code entirely where possible. The JQuery $.support property (if you want) is available for detection of support for particular features rather than relying on browser name and version.

Upvotes: 1

Related Questions