Skip to content Skip to sidebar Skip to footer

How To Use Multiple Different Localstorage In A Single Domain?

I have a website in which there are 3 different folders to be accessed by 3 different users. say if you accessed www.thissite.com/folder1/index.html it will check if user is logged

Solution 1:

LocalsStorage is name/value dictionary. If you just use the data name, you will override any previous values in it. Instead, use three different names (one for each folder) and set their data that way:

localStorage['folder1'] = JSON.strinfify({logedIn:1});
localStorage['folder2'] = JSON.strinfify({logedIn:0});
localStorage['folder3'] = JSON.strinfify({logedIn:1});

Alternatively, you could just create one object into localStorage and populate the different folders that way.

localSotrage['data']=JSON.stringify({folder1: {logedIn:1},folder2: {logedIn:0},folder3: {logedIn:1}
                       });

Post a Comment for "How To Use Multiple Different Localstorage In A Single Domain?"