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".
当用户单击其中一个链接时,弹出"窗口应该关闭,并返回允许"或不允许"或类似的内容,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...');
那么auth.php
里面只有2个锚点?
Then just 2 anchors inside 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>
这篇关于弹出窗口以在关闭时将数据返回给父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:弹出窗口以在关闭时将数据返回给父级


基础教程推荐
- fetch 是否支持原生多文件上传? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01