2014-02-22 101 views
0

通常情况下,当您需要管理新窗口时,它将使用open()方法,并且在需要管理父级时使用opener属性,如本例中:Javascript - 管理通过窗体打开的新窗口

var myWindow = window.open("", "myWindow", "width=200,height=100"); // Opens a new window 
myWindow.document.write("<p>This is 'myWindow'</p>");    // Text in the new window 
myWindow.opener.document.write("<p>This is the source window!</p>"); // Text in the window that created the new window 

当新的窗口已经被形式打开,如本例中的jQuery我的问题是:

$('#form1').html('<form id="f1" action="welcome.php" method="post" target="_blank"><input type="hidden" name="name" value="a"><input type="hidden" name="email" value="[email protected]"><input type="submit"></form>'); 
$("#f1").submit(); 

如何管理新的窗口(使用由target="_blank"),关联它在JavaScript中的新对象? 我需要将opener属性应用到由窗体打开的新窗口中...

+0

[这个答案](http://okwave.jp/ qa/q6731947.html)按名称显示引用窗口对象,“function getWindow”。如果可以设置名称而不是'_blank',则可以访问该窗口。 –

回答

0

如何在新窗口的javascript中将窗口对象设置为操作员窗口的属性?

在新窗口(在你的代码 “的welcome.php”):

$(document).ready(function() { 
    window.opener.newWindowObj = window; 
}); 

在揭幕战窗口:

// check window object exists 
alert(window.newWindowObj); 
+0

谢谢,但我不是服务器中的welcome.php的所有者(welcome.php,它只是一个例子,在真实的代码中它是另一个php文件) –