Listening for DOMContentLoaded event from child frame

61 Views Asked by At

I want to know when a navigation event occurs in a child frame, when the child frame's new document content has been loaded, but not wait for all the images and other resources to be loaded. (It is a legacy frameset document, though seems, in all major browsers, to generally behave as if it's a document containing iframes.)

Listening for the window.load event works, but the event is not triggered until all images etc. are loaded. Listening for the document.DOMContentLoaded does not. I have tried waiting for the first load event before setting the DOMContentLoaded event handler, but to no avail.

Is the problem that the document has been changed, so the original document that the event was attached to no longer exists? If so, is there a window event I can use that would trigger at the same time as DOMContentLoaded? Or do I need to use postMessage to achieve what I'm trying to do?

I'm looking for a quick answer from someone who knows. If it's possible to listen for DOMContentLoaded in this situation, I'd rather do that, than implement a postMessage solution unnecessarily.

The documents are same origin, so CORS is not an issue.

0

There are 0 best solutions below