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.

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 *