Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LocalStorage in chrome Incognito Mode

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 localStoarge and it works fine n incognito mode also.

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?

like image 325
StrugglingCoder Avatar asked Jul 01 '17 03:07

StrugglingCoder


1 Answers

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.

like image 62
will Avatar answered Oct 19 '22 19:10

will