Link to home
Start Free TrialLog in
Avatar of Abhilash Nagar
Abhilash Nagar

asked on

localStorage NULL in new tab

Hello,
I am setting

localStorage.setItem("userName",userStrName);

which is fine if it is a single tab. But as soon as new tab opens and i call

localStorage.getItem("userName");

it is null

Not sure why it is null in new tab.

Please suggest.
Avatar of Brian Tao
Brian Tao
Flag of Taiwan, Province of China image

Are the pages from the same web server?
Avatar of Abhilash Nagar
Abhilash Nagar

ASKER

Thanks for the response Brian.
The page which i am setting is in local file system but the page which opens in new tab is hosted in IIS web server.
retrieval of localStorage from another tab should just working well.

what you could have missed are:

1. the sequence of page loading, make sure you loaded the page that calling localStorage.setItem before localStorage.getItem
2. make sure both pages are refer to the same item, in this case: "userName"
3. make sure in the process of showing userName using localStorage.getItem, value of "userName" is not being overwritten or cleared.
4. make sure you got a modern web browser that support localStorage
ASKER CERTIFIED SOLUTION
Avatar of Brian Tao
Brian Tao
Flag of Taiwan, Province of China image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you ,really thanks for the response.
Ok sure, so I will then host all the files on IIS and will retry again , I think ,should work after that.
Thanks Brian, as you said i hosted both WEbAPI service and Webapplication , with the same IP address, it worked. Even if there is something like localhost in webapplication URL  and in webapi URL it is IPaddress, it was not working. I changed the webapplication to IPaddress rather then localhost so both are same, it started working then.
So you are right, really thanks for your help.
really thanks for your help.
No problem.  Glad to help.