Browser Detection via JS for Safari 5
How can I check if the user's c开发者_如何学Gourrent 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.
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.
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.
精彩评论