4

Ok, so I have several pages that use localStorage. On the first page it creates first item of localStorage:

$('#id').click(function(){
    localStorage.text = $(this).val();
});

This part of the code works fine in all browsers.

Now on the next page, I am adding more data to storage:

    $('#someid').click(function(e) {
// stores variables in localStorage
        localStorage.background = img;
        localStorage.fSize = fontSize;
        localStorage.text = t;
        localStorage.textX = Tx;
        localStorage.align = alignVal;
        localStorage.rotationAngle = Deg;

    window.location = 'somepage.php';

For some reason this part does not work in Firefox (any version), but works perfectly in IE and Chrome.

What could be the issue here? And could I fix it if use sessionStorage instead?

Thanks.

Ok. here is an update: I use localStorage variables to populate php form on second page and after that clear the storage. If I do not clear the storage - everything works just fine. Is there anyway to clear storage only after all variables have been copied to form?

7
  • 1
    Your img value is an URL or an actual image? localStorage can only take strings as values.
    – user1693593
    Commented Sep 24, 2013 at 6:12
  • all values are actual strings. Just as I said it works in any other browser, except Firefox. The main question is how to make it work in Firefox. Commented Sep 24, 2013 at 6:15
  • Are there any errors?
    – karaxuna
    Commented Sep 24, 2013 at 6:17
  • no, no errors. just an empty localStorage. even the item from the first page dissapears. Commented Sep 24, 2013 at 6:18
  • 2
    can you try delaying the redirect using setTimeout like setTimeout(function(){window.location = 'somepage.php';}, 2000) Commented Sep 24, 2013 at 7:00

1 Answer 1

2

I managed to get this to work in FireFox using the following code:

Preview: http://barriereader.co.uk/localstoragetest/

Code:

 $('#someid').on('click', function(e) {
        window.localStorage.setItem('background', img);
        window.localStorage.setItem('fSize', fontSize);
        window.localStorage.setItem('text', t);
        window.localStorage.setItem('textX', Tx);
        window.localStorage.setItem('align', alignVal);
        window.localStorage.setItem('rotationAngle', Deg);

        window.location = 'page2.html';
    });

and to retrieve and remove sequentially:

if (window.localStorage.getItem('background')) {
    var backgroundVariable = window.localStorage.getItem('background');
    window.localStorage.removeItem('background');
}
1
  • well in my case, I managed to fix it with just adding timeout function before redirecting to next page. Since one of variables was pretty big amount of data and as I guess Firefox just working with localStorage much slower than other browsers Commented Sep 29, 2013 at 15:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.