How do I check if user is using Safari on the Windows? Because I need to apply some special styles to the site.
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 do I detect the browser name ? You can use the navigator. appName and navigator. userAgent properties.
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With