14

So In my Angular 1.5 application, I want to retain data on page load also,

So I am using $window.localStorage.

I am reading some value from localStorage and it also works fine in incognito mode.

The page refreshes and yet the values are retained.

if($window.localStorage.selectedServers !== undefined)
    selectedObj = JSON.parse($window.localStorage.selectedServers);

The problem is

When I copy the Url and open in a new tab incognito itself,

The localStorage gets undefined.

How to get rid of this issue? Or what am I doing wrong?

Victor Zamanian
  • 3,100
  • 24
  • 31
StrugglingCoder
  • 4,781
  • 16
  • 69
  • 103
  • 9
    incognito mode will only keep/store the values temporarily, other 'tabs' will not have access. Your history will disappear too. There is no workaround (that I know of) – blurfus Jul 01 '17 at 04:27
  • Check out https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API – blurfus Jul 01 '17 at 04:33
  • 5
    Possible duplicate of [Web Storage (sessionStorage and localStorage) in private browsing mode (incognito)](https://stackoverflow.com/questions/26042423/web-storage-sessionstorage-and-localstorage-in-private-browsing-mode-incognit) – blurfus Jul 01 '17 at 04:33
  • I use LocalStorage to keep user ID. After each refresh the incognito takes the user id from the notmal window and keeps it (doesen't sync with the normal window). Is this espected? – profimedica Jan 28 '19 at 09:12

1 Answers1

13

When I copy the Url and open in a new tab incognito itself,

The localStorage gets undefined.

This is because as mentioned in the comments, incognito / private browsing windows will not retain local / session storage. Therefore when you open a new tab they are empty.

will
  • 944
  • 9
  • 18