I'm keeping track of child windows being opened from a parent page. The following code works as partially as expected, but with an important flaw. Whenever I execute the postback, it reloads the JavaScript and it erases the global variable.
My proposed solution
I thought of adding the object to the sessionStorage with the following line of code;
sessionStorage.setItem(thiskey, winInst);
However, I'm getting an error: JavaScript runtime error: Circular reference in value argument not supported.
The value being added is a window object.
Here's the working code without the sessionStorage line.
var openedWindows = {};
setInterval(checkIfWindowIsClose, 40);
function openThisWindow(popLoc, attributes, id) {
var winInst = window.open(popLoc, attributes, id);
openedWindows["clickedRow" + id] = winInst;
}
function checkIfWindowIsClose() {
var id = "";
for (var i in openedWindows) {
if (openedWindows[i].closed) {
console.log(i);
delete openedWindows[i];
id = (' ' + i).slice(1);
id = id.replace("clickedRow", "");
}
}
if (id !== "") {
__doPostBack('upList.UniqueID', id.toString());
id = "";
}
}
Goal
Keep track of the openedWindows dictionary after a page reload.
How can I achieve this with sessionStorage?
Thank you,