Iframe Onload Event

The iframe element has an onload event, and although the iframe onload attribute is not valid in HTML4, it is valid in HTML5. Here is an example:

<iframe id="ifrm" src="demo.html" onload="doSomething()"></iframe>

Instead of using the iframe tag's onload attribute, you can use JavaScript to assign a function to an iframe's onload event handler property:

<script type="text/javascript">
document.getElementById('ifrm').onload = function() {
    // put your awesome code here
}
</script>

Another option: you can include an onload handler in the iframed document itself. All browsers in current use support all three approaches.

Note: Onload events are fired on iframe elements before they are fired on the containing document. See iframe onload in use in Access to Iframe and Contents.