子窗口关闭时如何运行父窗口的功能? [英] How to run function of parent window when child window closes?

查看:154
本文介绍了子窗口关闭时如何运行父窗口的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调用javascript window.open()函数在弹出窗口中加载另一个url。用户完成后,将它们带到最后一个页面,该页面的链接显示调用window.close()函数的关闭窗口。现在,当该页面关闭时,我需要更新打开窗口的原始页面中的内容。有没有办法做到这一点?我必须调用我原始页面中的一个函数。

I am calling the javascript window.open() function to load another url in a pop up. Once the users is finished it takes them to the last page that has a link that says close window that calls the window.close() function. Now when that page closes I need to update something in the original page that opened the window. Is there any way to do this? I have to call a function that is in my original page.

推荐答案

你可以试试这个:

产生窗口:

window.onunload = function (e) {
    opener.somefunction(); //or
    opener.document.getElementById('someid').innerHTML = 'update content of parent window';
};

父窗口:

window.open('Spawn.htm','');
window.somefunction = function(){

}

你不应该在父级上执行此操作,否则opener.somefunction()将无效,
执行window.somefunction使某些功能成为公共:

You should not do this on the parent, otherwise opener.somefunction() will not work, doing window.somefunction makes somefunction as public:

function somefunction(){

}

这篇关于子窗口关闭时如何运行父窗口的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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