弹出窗口以在关闭时将数据返回给父级

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>

这篇关于弹出窗口以在关闭时将数据返回给父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)