Javascript序列化窗口对象 [英] Javascript serialize window object
问题描述
我想序列化一个包含窗口的窗口对象,因此如果通过反序列化并重新设置其属性来刷新php页面,则在内存中保持窗口打开。可能吗?
I would like to serialize a window object that contains a window, thus to keep in memory the window open if the php page is refreshed by deserializing it and setting its properties back. Is it Possible?
例如:
object = window.open( test.html,..)
使用场景:
当a窗口被打开,它的引用是在创建它的父窗口中进行的,但是当刷新该父窗口时,对子窗口的引用将丢失。因此,我想序列化该窗口对象并保留它以防刷新窗口。任何其他解决方案也是受欢迎的。
When a window is opened its reference is made in the parent window which created it, but when that parent window is refreshed that reference to the child window is lost. Therefore I want to serialize that window object and keep it in case the window is refreshed. Any other solution for this is also welcome.
推荐答案
不,你不能序列化一个窗口对象。这是因为窗口对象具有循环引用。对象的每个子节点都有对其父节点的引用。 JSON.stringify()
不支持循环引用。并且不要试图将引用保留在全局变量中。全局变量是全局对象的属性。此对象的属性是JavaScript程序的全局变量。当您声明一个全局JavaScript变量时,您实际要做的是定义全局对象的属性。
No, you can´t serialized a window object. And that's because a window object has circular references. Every child of an object has a reference to his parent. JSON.stringify()
does not support circular references. And do not try to keep the reference in a global variable. Global variables are properties of a global object. The properties of this object are the global variables of JavaScript programs. When you declare a global JavaScript variable, what you are actually doing is defining a property of the global object.
有关详细信息,请检查此链接。
For more info please check this link.
这篇关于Javascript序列化窗口对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!