views:

51

answers:

2

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.

+1  A: 
Sarfraz
A: 

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.

ob1