Edge 的 composedPath 的替代方案
Alternative to composedPath for Edge
我希望能够在使用 Edge/IE 单击某处时检测到路径。使用all other browsers I can use event.composedPath(),但Edge和IE不支持。
我一直在四处寻找,我只是 不鼓励使用 path
而是使用 composedPath()
,但我没有找到任何关于 Edge 的参考。
请帮忙!
您可以尝试检查这个 polyfill 可能有助于获得组合路径。
// Event.composedPath
(function(e, d, w) {
if(!e.composedPath) {
e.composedPath = function() {
if (this.path) {
return this.path;
}
var target = this.target;
this.path = [];
while (target.parentNode !== null) {
this.path.push(target);
target = target.parentNode;
}
this.path.push(d, w);
return this.path;
}
}
})(Event.prototype, document, window);
像下面这样使用它:
var path = event.path || (event.composedPath && event.composedPath());
参考文献:
(1)
(2) rockinghelvetica/composedpath.polyfill.js
除此之外,我没有任何替代方法或解决方法来为 IE 和 Edge 浏览器获取 Event.Composedpath。
我希望能够在使用 Edge/IE 单击某处时检测到路径。使用all other browsers I can use event.composedPath(),但Edge和IE不支持。
我一直在四处寻找,我只是 path
而是使用 composedPath()
,但我没有找到任何关于 Edge 的参考。
请帮忙!
您可以尝试检查这个 polyfill 可能有助于获得组合路径。
// Event.composedPath
(function(e, d, w) {
if(!e.composedPath) {
e.composedPath = function() {
if (this.path) {
return this.path;
}
var target = this.target;
this.path = [];
while (target.parentNode !== null) {
this.path.push(target);
target = target.parentNode;
}
this.path.push(d, w);
return this.path;
}
}
})(Event.prototype, document, window);
像下面这样使用它:
var path = event.path || (event.composedPath && event.composedPath());
参考文献:
(1)
(2) rockinghelvetica/composedpath.polyfill.js
除此之外,我没有任何替代方法或解决方法来为 IE 和 Edge 浏览器获取 Event.Composedpath。