Categories
JavaScript Answers

How to check if iframe is loaded or it has a content with JavaScript?

Spread the love

Sometimes, we want to check if iframe is loaded or it has a content with JavaScript.

In this article, we’ll look at how to check if iframe is loaded or it has a content with JavaScript.

How to check if iframe is loaded or it has a content with JavaScript?

To check if iframe is loaded or it has a content with JavaScript, we can set the iframe’s onload property to a function that runs when the iframe is loaded.

For instance, we write

document.querySelector("iframe").onload = () => {
  console.log("iframe loaded");
};

to select the iframe with querySelector.

Then we set its onload property to a function that runs when the iframe’s content is loaded.

Conclusion

To check if iframe is loaded or it has a content with JavaScript, we can set the iframe’s onload property to a function that runs when the iframe is loaded.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.