Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detection for Safari Windows with Javascript

How do I check if user is using Safari on the Windows? Because I need to apply some special styles to the site.

like image 468
Stickers Avatar asked Jun 01 '12 14:06

Stickers


People also ask

Can I detect the browser with JavaScript?

Browser Detection with JavaScript. If you really must do it, detecting what browser someone is using is easy with JavaScript. JavaScript has a standard object called navigator that contains data about the browser being used.

How can you detect the client's browser name JavaScript?

How do I detect the browser name ? You can use the navigator. appName and navigator. userAgent properties.


1 Answers

You can test navigator.userAgent for the strings Safari/ and Windows (list of Safari user agent strings), e.g.: Live Example

var ua = navigator.userAgent.toLowerCase();
if (ua.indexOf("safari/") !== -1 &&  // It says it's Safari
    ua.indexOf("windows") !== -1 &&  // It says it's on Windows
    ua.indexOf("chrom")   === -1     // It DOESN'T say it's Chrome/Chromium
    ) {
    // Looks like Safari on Windows (but browser detection is unreliable and best avoided)
}

...but browser detection is usually not the best solution to a problem. Much better, where you can, to use feature detection. You can feature-detect nearly everything. Kangax has a great list of feature detects, and of course libs like Moderizr do them as well. But I don't know your use-case...

like image 150
T.J. Crowder Avatar answered Sep 25 '22 19:09

T.J. Crowder