0

I am using

window.open(newTabUrl, "toolbar=yes,scrollbars=yes,resizable=yes", "width=500,height=500");

which is working fine if I did not refresh page.

But I want to maintain this value in one variable and set in the local storage. When I go to another page, if new window is opened I want to refresh that new window when I open new document. This is working if I am in the same page.

I am using this code to set value in the local storage:-

myWindow = window.open(newTabUrl, "toolbar=yes,scrollbars=yes,resizable=yes", "width=500,height=500");

newDocumentWindow = true;
localStorage.setItem("newDocumentWindow", newDocumentWindow);
localStorage.setItem("myWindow", myWindow);

When page is refreshing I am using

var myWindow = localStorage.getItem("myWindow");

It gives me ["object window"]

When I am assigning this code to refresh page like this:

myWindow.location.href = newTabUrl;
myWindow.focus();

It is not working. Please help me how to store window.open value in local storage and get value from local-storage during page refresh.

mplungjan
  • 169,008
  • 28
  • 173
  • 236
Neelam
  • 33
  • 7
  • As of now, it's only possible to store strings in localstorage, see this question: http://stackoverflow.com/questions/2010892/storing-objects-in-html5-localstorage – Esko May 22 '17 at 09:45
  • Store "toolbar=yes,scrollbars=yes,resizable=yes" and "width=500,height=500" their own variables in local storage not the whole window.open – Deckerz May 22 '17 at 09:46
  • the second argument of window open is the name of the window. `window.open(newTabUrl, "myWindowName","toolbar,....")` If you store the `myWindowName` in local storage, you can get the handle again from the same origin using `var myWindow = window.open(newTabUrl, localStorage.getItem("popupName"));` or without localStorage as `var myWindow = window.open(newTabUrl, "myWindowName");` – mplungjan May 22 '17 at 09:48
  • @mplungjan Can you explain me more using sample code. – Neelam May 22 '17 at 09:57
  • `var windowName="myPopup", myWindow = window.open(newTabUrl, windowName,"toolbar,scrollbars,resizable,width=500,height=500");` then later you can do `myWindow=window.open("",windowName); myWindow.location.href=newTabUrl;` - please note the syntax of the window.open which in your example is wrong – mplungjan May 22 '17 at 11:14

0 Answers0