0

If you have a minute, I am trying this...

    var parentWin=window.opener;

    sessionStorage.setItem("TempWin",parentWin);

    parentWin=sessionStorage.getItem("TempWin");

    alert(parentWin.location.href);

But it's saying null object on the alert. Is it not possible to store a window in sessionStorage? Thank you very much.

Don Holmes
  • 23
  • 2
  • 7
  • *"Is it not possible to store a window in sessionStorage?"* No, [`Storage`](https://developer.mozilla.org/en-US/docs/Web/API/Storage) objects (`sessionStorage`, `localStorage`) only store **strings**. From [`setItem`](https://developer.mozilla.org/en-US/docs/Web/API/Storage/setItem): *"**`keyValue`** - A DOMString containing the value you want to give the key you are creating/updating."* – T.J. Crowder Feb 08 '22 at 16:03
  • 1
    Related: [1](https://stackoverflow.com/questions/28926997/how-to-have-localstorage-value-of-true), [2](https://stackoverflow.com/questions/36103575/can-i-store-entire-label-to-sessionstorage), [3](https://stackoverflow.com/questions/51403516/saving-and-getting-an-array-in-localstorage), [4](https://stackoverflow.com/questions/23449017/html5-local-storage-using-javascript) – T.J. Crowder Feb 08 '22 at 16:06
  • Thanks. I tried to store in JSON as well (stringify, parse) but that won't take circular objects. Is there any way to persist a js window object across a page reload? It's not looking good. – Don Holmes Feb 08 '22 at 16:10
  • 1
    No, there isn't. Window objects aren't serializable (certainly not to JSON, but not in the general case either). – T.J. Crowder Feb 08 '22 at 16:24
  • Thanks. What is happening here is that I have a grandparent window, parent window, current window. In current window, on load event, I set grandparentWindow object based on parent. The current window reloads after submitting but if I close parent window before the reload, the ties to grand parent are lost. I'm trying to persist that grand parent window object in current window and access it post reload. – Don Holmes Feb 08 '22 at 16:35

0 Answers0