Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

localStorage not storing persistently between two pages

I'm developing an application and, at certain point, I need to store information that requires to be persistent between multiple pages, more probably, it will only be 2 pages. The amount of information varies between just a few bytes and about 15KB (It will never be more than 20KB, ever). I can't really properly predict beforehand how much it will be.

For that I decided to use localStorage.

For now I'm only working on localhost:8080.

The pages, for now have only generic names: pageA.php and pageB.php.

The pages reside on the root of the domain. I.e.

http://localhost:8080/pageA.php
http://localhost:8080/pageB.php

...

At certain times, I store data on localStorage, on pageA.php (I do use the setItem() method).

When the user moves to pageB.php, pageB.php's script then tries to get the data that was stored in pageA.php.
The problem is that getItem() always returns null on pageB.php

I did check the keys I'm using and they are the same, so there should be no problems there.

I've checked, data stored is persisting between page loads as long as the url does not change.

What am I doing wrong here?

Note: tested only on Firefox 19 and on chrome 24

like image 962
brunoais Avatar asked Feb 24 '13 12:02

brunoais


1 Answers

The problem here was that the editor I was using had been changed such that it was searching with case sensitivity.
When I changed the string i was using for the key, the replacer didn't match all the strings due to case sensivity.
I solved it by searching and adapting each key such that all keys had the same characters with the same case, not the same characters regardless of case.
In the in the end, it was just lack of attention. As expected, strings in javascript are case sensitive and that also applies to the key for localStorage and sessionStorage

like image 184
brunoais Avatar answered Nov 06 '22 22:11

brunoais