Reputation: 19366
How can I fire something on the last in a series of load
events? I'm loading multiple iframes and need to fire a function when all the iframes have finished loading. So I need to bind the function to the last iframe loaded's load
event.
Is this possible? I don't want to force synchronous loading if possible.
Upvotes: 3
Views: 589
Reputation: 78840
A simpler way to solve the problem would be to attach the same load handler to all of the iframes, maintain a counter, then run your code once the required number of load events have taken place:
<iframe src="url1" onload="onFrameLoaded();"></iframe>
<iframe src="url2" onload="onFrameLoaded();"></iframe>
<iframe src="url3" onload="onFrameLoaded();"></iframe>
<script type="text/javascript">
var loadedCount = 0;
function onFrameLoaded() {
loadedCount++;
if (loadedCount >= 3) {
// Do your thing
}
}
</script>
Upvotes: 7