Detection for Safari Windows with Javascript

2020-07-17 14:31发布

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

2条回答
叛逆
2楼-- · 2020-07-17 15:00

This plugin seems to be exactly what you want. Plugin Link

On the plugin page they link to a test page that runs the plugin which will shoot back the browser and OS. Test Link

查看更多
Root(大扎)
3楼-- · 2020-07-17 15:05

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...

查看更多
登录 后发表回答