弹出窗口在关闭时将数据返回到父级 [英] Popup window to return data to parent on close
本文介绍了弹出窗口在关闭时将数据返回到父级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经使用 window.open()
打开了一个弹出窗口。我现在想要的是让用户能够点击这个新窗口中的2个链接之一:允许或不允许。
I've got a popup window opened using window.open()
. What I want now is for a user to be able to click one of 2 links within this new window: "Allow" or "Don't Allow".
当a用户单击弹出窗口应关闭的其中一个链接,并返回允许或不允许或沿着这些行的某些内容, true
/ false
会对父窗口产生影响。
When a user clicks one of those links the 'popup' window should close, and return either "allow" or "don't allow" or something along those lines, true
/false
would do, to the parent window.
有可能吗?如果是这样,怎么样?
Is it possible? If so, how?
代码:
var authWindow = window.open('auth.php', 'authWindow', 'options...');
然后只需2个锚点 auth.php
?
推荐答案
在调用(父)窗口中添加这样的JS代码:
In the calling (parent) window add such JS code:
function HandlePopupResult(result) {
alert("result of popup is: " + result);
}
在子窗口代码中添加:
function CloseMySelf(sender) {
try {
window.opener.HandlePopupResult(sender.getAttribute("result"));
}
catch (err) {}
window.close();
return false;
}
并且有这样的链接可以关闭弹出窗口:
And have such links to close the popup:
<a href="#" result="allow" onclick="return CloseMySelf(this);">Allow</a>
<a href="#" result="disallow" onclick="return CloseMySelf(this);">Don't Allow</a>
这篇关于弹出窗口在关闭时将数据返回到父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文