Sometimes, we want to check if parent window is iframe or not with JavaScript.
In this article, we’ll look at how to check if parent window is iframe or not with JavaScript.
How to check if parent window is iframe or not with JavaScript?
To check if parent window is iframe or not with JavaScript, we use ther window.frameElement property.
For instance, we write
const isInIframe =
window.frameElement && window.frameElement.nodeName === "IFRAME";
to check if the nodeName property of the window.frameElement object if 'IFRAME'.
If it is, then the parent window is an iframe.
Conclusion
To check if parent window is iframe or not with JavaScript, we use ther window.frameElement property.