刷新后检索子窗口引用 [英] Retrieve child window reference after refresh

查看:90
本文介绍了刷新后检索子窗口引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 HTML5离线应用程序(即没有服务器端组件/代码)。

I have an HTML5 offline app (i.e. there's no server-side component/code).

它基本上有两个窗口和孩子)。但是,在某些情况下,我需要以编程方式刷新父窗口。当这种情况发生时,它失去了对孩子的引用,孩子对window.opener的引用已不再有效。所以我的想法是我将序列化子窗口并将其存储在localStorage中。然后,当父级刷新时,它可以从localStorage接收窗口引用,并仍然与孩子交互。

It basically has two windows (parent and child). However, in some instances I need to programmatically refresh the parent window. When this happens, it loses its reference to the child, and the child's reference to window.opener is no longer valid. So my thinking was that I'd serialize the child window and store that in localStorage. Then when the parent refreshed it could pick up the window reference from localStorage and still interact with the child.

问题是这不工作(根据我以前的这里的问题是 Stringify DOMWindow对象)。我无法像任何其他对象序列化DOM窗口。

The problem is that this doesn't work (as per my previous question here Stringify DOMWindow object). I can't serialize a DOM window like any other object.

那么我怎么能让我刚刚刷新的窗口拿起它的前辈的孩子呢?

So how can I have my newly refreshed window pick up a reference to its predecessor's child?

编辑:强调这是一个离线应用程序。没有服务器端组件。

Edit: Stressed the fact that it's an offline app. There's no server-side component.

我还应该补充说,我需要刷新父代的原因是检查应用程序更新(缓存清单中的更改)。由于父代是加载应用程序的第一页,它基本上管理缓存(实际上在Safari中,如果此窗口在任何缓存过程中关闭,整个浏览器崩溃)。所以父本质上是用户加载的第一页。 这意味着我不能在一个框架中拥有父,因为最上面的窗口将管理缓存,并且需要刷新才能查找更新。实际上,似乎我可以使用frame方法,因为刷新应用程序中的任何页面将触发更新检查。

I should also add that the reason I need to refresh the parent is to check for application updates (changes in the cache manifest). Since the parent is the first page in the application that loads, it basically manages the caching (in fact as an aside, in Safari if this window is closed during any of the caching process the entire browser crashes). So "parent" is essentially "first page that the user loads". This means that I can't have the "parent" in a frame, as the topmost window would then manage the caching, and require the refresh in order to look for updates. Actually, it appears that I can use the frame method, as refreshing any of the pages in the application will trigger the update check. Cumbersome though.

推荐答案

参见这里: http://www.w3.org/TR/html5/offline.html#dom-appcache-update

applicationCache.addEventListener("updateready", function() {
  applicationCache.swapCache();
  //now reload the body html
}, false);
setInterval(60000, applicationCache.update);//check for updates every minute

updateready 每次下载新版本时都会触发)

(updateready fires every time a new version has been downloaded)

这篇关于刷新后检索子窗口引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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