A B
A B

Reputation: 1

How to detect if iframe's source page is fully loaded into DOM

I want an event to fire after iframe's source page is loaded into DOM to do some customization client side. Please help me.

Upvotes: 0

Views: 46

Answers (2)

T.J. Crowder
T.J. Crowder

Reputation: 1075795

If the iframe's content is from the same origin as the containing page, you can listen for the DOMContentLoaded event on it:

theFrame.documentWindow.addEventListener("DOMContentLoaded", function() {
    // ...
});

(If the content isn't from the same origin, I don't think you can hook that event — but that doesn't matter, because you wouldn't be able to do the customization you've mentioned, either. :-) )

Upvotes: 2

FZs
FZs

Reputation: 18639

Use onload event:

document.getElementById("iframe-id").addEventListener("load",event=>{
    //Do some stuff when iframe loaded
})

Upvotes: 1

Related Questions