Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if an element is inside an iframe or not

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.

like image 312
user730569 Avatar asked Oct 24 '25 13:10

user730569


1 Answers

You could probably check the ownerDocument property of the node:

if(node.ownerDocument !== document) {
    // node must be inside iframe
}
like image 195
Felix Kling Avatar answered Oct 27 '25 02:10

Felix Kling



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!