子窗口关闭时可以通知父窗口吗? (在diff域上) [英] Can the parent window be notified when a child window closes? (on a diff domain)

查看:144
本文介绍了子窗口关闭时可以通知父窗口吗? (在diff域上)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

子窗口关闭时是否可以通知父窗口? (在不同的域?)

Can the parent window be notified when a child window closes? (on a different domain?)

尝试围绕window.opener在不同的域上工作。

Trying to get around the window.opener not working when on different domains.

当子窗口关闭时,至少可以通知您吗?

Can I at least be notified somehow when the child window closes?

推荐答案

您不能直接收到窗口的通知关闭,但您可以通过检查 <$ c $关闭子窗口来解决问题在 属性rel =noreferrer > window.open()

You can't directly be notified of the window closing, but you can work out when the child window has been closed by inspecting the closed property on the window object reference returned by window.open().

这是一个在5秒内显示警报的示例通过轮询关闭的子窗口关闭属性:

Here's an example that will display an alert within 5 seconds of the child window being closed by polling the closed property:

var win = open('http://www.google.com');
var intervalId = setInterval(function() {
        if (win.closed) {
            clearInterval(intervalId);
            alert('Window closed! Hoorah!');
        }
    }, 5000);

这篇关于子窗口关闭时可以通知父窗口吗? (在diff域上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆