Reputation: 21666
I'm opening a window as
winRef = window.open(......);
Then I'm storing the above winRef
in cookie so that I can get the reference to child window even if the parent refreshes.
That didn't work because when I tried to save winRef in cookie it just saves the text representation/string
of the object so you only have "[object Window]"
as string, it's not an object.
Is there any way to store the window reference as a cookie? If it's not possible then what are some other possible methods which I can use?
PS: I think storing just the window name instead of window object in the cookie can solve the issue but it can't be done in my case, I can't provide window names, basically the window is an online editor, if I give a particular name to it then user can't open multiple online editors as it will always reload the currently opened window.
Ultimate goal: Retrieving references to child window if the parent refreshes
Upvotes: 2
Views: 3081
Reputation: 61
First excuse me for my poor English ;-)
A possible workaround for this problem is to set a name in the window.open function (eg: popup = window.open(URL, popup_window, specs, replace)
Then save popup in a cookie.
When retrieving the cookie, you'll get the [object Window]
as you said.
eg: popup = getCookie('popup');
After just do the following :
if (popup == null) {
//No popup
} else {
//Popup exist, retrieving is ref
popup = window.open("" ,"popup_window");
}
Just reuse the window.open
function, just with the same name (popup_window
) and no other arguments, as this window already exist no further actions will be performed just returning the popup_window
ref.
Upvotes: 6
Reputation: 146450
Variables are abstractions that live on primary memory (aka RAM) and in the scope of a running process or thread. You just can't store them anywhere else.
Particularly, cookies are plain text. They are sent as HTTP headers and they're often stored in text files. So to answer your question: no, you cannot store a JavaScript object of type window
in a cookie.
Upvotes: 3