Sometimes, we want to listen to iframe onload JavaScript event.
In this article, we’ll look at how to listen to iframe onload JavaScript event.
How to listen to iframe onload JavaScript event?
To listen to iframe onload JavaScript event, we set the iframe’s onload property to a function that’s called when the iframe is loaded.
For instance, we write
<iframe id="my_iframe" src="http://www.exanple.com/"> </iframe>
to add an iframe.
Then we write
document.getElementById("my_iframe").onload = () => {
//...
};
to select the iframe with getElementById.
Then we set its onload property to a function that’s called when the iframe’s contents is loaded.
Conclusion
To listen to iframe onload JavaScript event, we set the iframe’s onload property to a function that’s called when the iframe is loaded.