<iframe> for this load element.
How do you listen that this event is up to you, but usually the best way:
1) create your iframe programmatically
This ensures that your load listener is always called by attaching it before the iframe starts loading.
<script> var iframe = document.createElement('iframe'); iframe.onload = function() { alert('myframe is loaded'); }; </script>
2) built-in javascript , this is another way you can use in your HTML markup.
<script> function onMyFrameLoad() { alert('myframe is loaded'); }; </script> <iframe id="myframe" src="..." onload="onMyFrameLoad(this)"></iframe>
3) You can also attach an event listener after the element in the <script> , but keep in mind that in this case there is little chance that the iframe is already loaded by the time your listener is added. Therefore, it is possible that it will not be called (for example, if iframe is very fast or goes out of cache).
<iframe id="myframe" src="..."></iframe> <script> document.getElementById('myframe').onload = function() { alert('myframe is loaded'); }; </script>
Also see my other answer about which elements can also trigger this type of load event.
galambalazs Jun 29 '10 at 16:57 2010-06-29 16:57
source share