window.open和$(document).ready

我正在尝试制作一个打开弹出窗口的书签。 在此窗口中是一个选定的CSS类列表,在window.opener页面上突出显示该对象。 所以我遇到了两个问题。

  1. Firebug在弹出窗口中不起作用,所以我看不到发生了什么。
  2. 窗口永远不会完成加载(至少我可以在Firefox中告诉)所以窗口内的$(document).ready(function(){...})永远不会被执行。

我无法从远程位置打开弹出窗口,因为我遇到了跨域问题。 以下是一些示例代码:

  function makepopup(){ var popup = '' + 'Test' + '' + '' + '
' + 'testing popup' + '
' + '' + '' + '$(document).ready(function(){' + '$(":input").click(function(){ alert($(window.opener.doc'+'ument).find("#test").html()) });' + '})' + '' + ''; var testpopup = window.open( '','test','toolbar=1,location=0,status=0,width=500,height=450,scrollbars=1' ); testpopup.document.write(popup); return false; } Open popup
This is hidden text

如果我在弹出窗口$(":input").click(function(){ alert($(window.opener.document).find("#test").html()) });中将以下内容添加到控制台中$(":input").click(function(){ alert($(window.opener.document).find("#test").html()) }); ,它工作正常,所以我确定它是文件。从来没有被调用过

或者,有更好的方法吗?

如果在return false之前添加以下行, $(document).ready是否会触发?

 testpopup.document.close(); 

这是一个疯狂的猜测,我没有测试过这个。

确实这个document.ready从来没有开过..( 我不知道为什么……

但是您可以在html之后添加脚本并删除document.ready因为文档总是在那时加载。

 function makepopup(){ var popup = '' + 'Test' + '' + '' + '
' + 'testing popup' + '
' + '' + '
'+ '' + '$(":input").click(function(){ alert($(window.opener.doc'+'ument).find("#test").html()) });' + ''; var testpopup = window.open( '','test','toolbar=1,location=0,status=0,width=500,height=450,scrollbars=1' ); testpopup.document.write(popup); return false; }​

这有效..

[更新]从Aistina手中保持这个方法是正确的方法。