在javascript中检测Safari浏览器

在javascript中检测Safari浏览器,javascript,regex,safari,detection,Javascript,Regex,Safari,Detection,我发现了以下代码片段,用于检查是否使用了Safari浏览器: var isSafari = /constructor/i.test(window.HTMLElement); 但我真的不知道这里发生了什么。有人能给我解释一下它是怎么工作的吗?我知道constructor返回创建RegExp对象原型的函数,并且I执行不区分大小写的匹配,但是HTMLElement到底是什么?在safari中,窗口。HTMLElement返回一个名为HTMLElementConstructor的函数 让我们这样做:

我发现了以下代码片段,用于检查是否使用了Safari浏览器:

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

但我真的不知道这里发生了什么。有人能给我解释一下它是怎么工作的吗?我知道
constructor
返回创建RegExp对象原型的函数,并且
I
执行不区分大小写的匹配,但是
HTMLElement
到底是什么?

在safari中,
窗口。HTMLElement
返回一个名为
HTMLElementConstructor
的函数

让我们这样做:

/constructor/i.test(function HTMLElementConstructor() {}) // return true
但对于其他浏览器(FF、Chrome),它会返回
HTMLElement

/constructor/i.test(function HTMLElement() {}) // return false

但是谢谢你的观察!我希望我们可以像这里提到的方法一样使用它:

在safari中,
窗口。HTMLElement
返回一个名为
HTMLElementConstructor
的函数

让我们这样做:

/constructor/i.test(function HTMLElementConstructor() {}) // return true
但对于其他浏览器(FF、Chrome),它会返回
HTMLElement

/constructor/i.test(function HTMLElement() {}) // return false

但是谢谢你的观察!我希望我们可以像这里提到的方法一样使用它:

这在iOS 11上不再适用(可能更早?)这在iOS 11上不再适用(可能更早?)