如何使用Javascript检测Safari 10浏览器? [英] How to detect Safari 10 browser in Javascript?

查看:83
本文介绍了如何使用Javascript检测Safari 10浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用

var isSafari = /constructor/i.test(window.HTMLElement)

,但不适用于新的Safari 10。

but it's not working for new Safari 10.

关于以下任何建议

谢谢!

编辑:如何检测Safari,Chrome,IE,Firefox和Opera浏览器?仅涵盖Safari版本以下9

edit: How to detect Safari, Chrome, IE, Firefox and Opera browser? only covers Safari up to version 9

推荐答案

var isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || safari.pushNotification);

将涵盖Safari的所有版本,从3.0到10(不是11)。

Will cover all version of Safari from 3.0 and until 10 (not 11).

它仅检查Safari中常见的两个API转换。在9.1.3之前的版本中, HTMLElement 对象的 .toString()结果为 [对象HTMLElementConstructor] ,这对于Safari是唯一的。在9.1.3之后的版本中已修复此问题。

It checks for two API diversion prevalent on Safari only. In versions before 9.1.3, the .toString() result of HTMLElement object is [object HTMLElementConstructor] and is unique to Safari. This was fixed in versions after 9.1.3.

对于较新的版本,请检查 [object SafariRemoteNotification] 对象这是仅在现代Safari浏览器中存在的对象类型。

For newer versions, check against the [object SafariRemoteNotification] object which is an object type that exists only in modern Safari browsers.

这篇关于如何使用Javascript检测Safari 10浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆