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.