jQuery:在子窗口上接收文件ready()

mrm*_*vin 12 jquery dom window ready

我正在尝试在我打开的子窗口加载并准备好其文档时收到通知.这似乎不起作用:

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
    });
Run Code Online (Sandbox Code Playgroud)

我需要做什么?

pol*_*lau 10

你试过这个吗? -

$(win.document).ready(function() {
    $(win.document).contents().find("...").doStuff();
});
Run Code Online (Sandbox Code Playgroud)

这个问题讨论的内容非常相似.重复?

  • 是的,它适用于手动javascript,谢谢!不得不这样做:win.onload = function(){form = $(this.document.getElementById(form_id)); form.submit(函数(EVT){ (5认同)
  • 是的我也尝试过.如果我的测试中的结果是正确的,那么问题是在DOM树尚未准备好的情况下触发ready()函数. (4认同)
  • 这不起作用,win.onload = function(){}是必需的 (2认同)

Gun*_*nni 6

我遇到了类似的问题,对我而言,窗口上的.load事件确实有效,而.ready则没有.所以你可以尝试:

win = window.open(href, 'test', 'width=300, height=400');
$(win).load(function() {
    $(this).contents().find("...").doStuff(); 
});
Run Code Online (Sandbox Code Playgroud)