Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: receive document ready() on child window

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?

like image 926
mrmclovin Avatar asked Jan 30 '11 10:01

mrmclovin


2 Answers

Have you tried this? —

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

This question discusses something very similar. Duplicate?

like image 185
polarblau Avatar answered Oct 12 '22 23:10

polarblau


I had a similar problem and for me the .load event on the window did work, the .ready did not. So you may try:

win = window.open(href, 'test', 'width=300, height=400');
$(win).load(function() {
    $(this).contents().find("...").doStuff(); 
});
like image 33
Gunni Avatar answered Oct 12 '22 23:10

Gunni