jQuery:在子窗口上接收文档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 });
我需要做什么?
你试过这个吗? –
$(win.document).ready(function() { $(win.document).contents().find("...").doStuff(); });
这个问题讨论了一些非常相似 重复?
我遇到了类似的问题,对我而言,窗口上的.load事件确实有效,而.ready则没有。 所以你可以尝试:
win = window.open(href, 'test', 'width=300, height=400'); $(win).load(function() { $(this).contents().find("...").doStuff(); });
在站点上的脚本中使用window.opener
,您正在加载并执行在第一页的global(!)中定义的函数。
主页:
打开页面:
Popup site
只需在iframe中添加此代码,
$(document,parent.document).ready(function(){ alert('Done'); });