Javascript:持久化窗口对象引用?

编程入门 行业动态 更新时间:2024-10-28 19:29:56
本文介绍了Javascript:持久化窗口对象引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的javascript代码打开了一些窗口:

My javascript code open some windows trough:

var win = window.open();

我将win参与存储在一个包含所有其他打开窗口的数组中。 一切正常,直到开启者刷新。

I store the win refernce in an array with all the other opened windows. Everything works fine, until the opener is refreshed.

所以我想要获得的是当主人时取回所有对已打开窗口的引用窗口已加载。

So what i'd like to achive is to get back all the references to the opened windows when the "master" window is loaded.

为了实现这一点,我必须: 1.在卸载时保留所有引用 2.在load $上获取引用b $ b 3.使用新的开瓶器更新参考资料

To realize this i have to: 1. persist all the references on unload 2. get back the references on load 3. update the references with the new opener

有可能吗?如果是这样的话?

Is it possible? if so how?

推荐答案

我是如何解决这个问题的。

How I solved the issue.

子窗口opener属性保持对打开它的WINDOW的引用,因此当刷新主窗口时窗口不会改变,因此开启者引用仍然是相同的。 当opener为null时唯一的情况是窗口关闭时*

The child window "opener" property keeps a reference to the WINDOW that opened it, so when the master window is refreshed the window doesn't change, so the opener reference is still the same. The only case when the opener is null is when the window is closed*

在主窗口的unload事件中,我调用了一个javaScript函数设置超时的子窗口。当超时结束时,我测试开启者引用并尝试注册,因为引用仍然正确。

On the unload event of the master window, I call a javaScript function on the child window that sets a timeout. When the timeout ends I test the opener reference and try to register back because the reference is still correct.

这样我就有了所有的子引用! ;)

当然,如果主窗口中加载的文档不是我的文档,但是,例如,www.google注册了儿童参考失败。

Of course, if the document loaded in the master window is not my document, but, for example, www.google registering back the child reference fails.

此解决方案已在Firefox,IE和Chrome下测试。

This solution has been teste under Firefox, IE and Chrome.

*在Chrome时你键入一个新的地址,它开始一个新的窗口,因此开启者也将为空。

*in Chrome when you type a new address it start a new window, so opener will be null as well.

更多推荐

Javascript:持久化窗口对象引用?

本文发布于:2023-05-23 14:46:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1326177.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:持久   对象   窗口   Javascript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!