如何检查元素是否在iframe中 [英] How to check if an element is inside an iframe or not
本文介绍了如何检查元素是否在iframe中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ownerDocument
属性节点:$ b $ b
if(node.ownerDocument!== document){
//节点必须在iframe内
}
Let's say you have a DOM node and you want to know whether it is located inside an iframe or not. One way would be to check it's parent chain to see if you reached an iframe before reaching the parent window. However, I'd like to know if there is a faster way to do this.
解决方案
You could probably check the ownerDocument
property of the node:
if(node.ownerDocument !== document) {
// node must be inside iframe
}
这篇关于如何检查元素是否在iframe中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文