Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript serialize window object

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?

for example:

object = window.open("test.html",..)

Usage Scenario:

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.

like image 325
Mohsin Sheikh Khalid Avatar asked Sep 01 '25 01:09

Mohsin Sheikh Khalid


1 Answers

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.

like image 135
Matías Galli Avatar answered Sep 02 '25 16:09

Matías Galli