Categories
JavaScript Answers

How to check if parent window is iframe or not with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *