Detection for Safari Windows with Javascript

a 夏天 提交于 2019-12-06 05:45:44

问题


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


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/10851954/detection-for-safari-windows-with-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!