检查一个DOM节点是否在一个iframe内 [英] Check to see if a DOM node is inside an Iframe
本文介绍了检查一个DOM节点是否在一个iframe内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查一下DOM Node是否在我应用程序的iFrame内。有没有办法找到节点所在的窗口?
I would like to check to see if a DOM Node is inside an iFrame in my application. Is there anyway to find what window the node resides in?
推荐答案
if (node.ownerDocument.defaultView.frameElement)
// We're inside of an <iframe>
代码说明:
node.ownerDocument.defaultView.frameElement
// ^------------------------------------------ The document of the <iframe>.
// ^ --------------------------- The window of the <iframe>
// ^---------------- The <iframe>
这篇关于检查一个DOM节点是否在一个iframe内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文