jQuery: receive document ready() on child window

mrmclovin picture mrmclovin · Jan 30, 2011 · Viewed 28.1k times · Source

I'm trying to get notified when the child window I'm opening has its document loaded and ready. This doesn't seem to work:

win = window.open(href, 'test', 'width=300, height=400');
win.focus();
$(win.document).ready(function() {
           // Ok, the function will reach here but if I try to manipulate the
           // DOM it doesn't work unless I use breakpoints
           $(this).contents().find("...").doStuff(); // nothing happens
    });

What do I have to do?

Answer

polarblau picture polarblau · Jan 30, 2011

Have you tried this? —

$(win.document).ready(function() {
    $(win.document).contents().find("...").doStuff();
});

This question discusses something very similar. Duplicate?