0

I have a dialog page that's saving the address and port of a server in localStorage:

localStorage.SERVER['address'] = address;
localStorage.SERVER['port'] = port;

I've cut my subsequent request down to just console logging the data in localStorage to check things are working.

$("#login_submit").click(function(event) {
    event.preventDefault();

    console.log(localStorage.SERVER['address'] + ' ' + localStorage.SERVER['port']);
}

What's happening though is that this executes fine when I submit the form without anything in localStorage (I get 'undefined undefined'). However after i've saved some values in the localStorage SERVER object the form reverts to behaving as normal and tries to open

http://mydomain/?username=&password= 

and doesn't log anything to the console.

ubiQ
  • 791
  • 2
  • 7
  • 17
  • You need to hook into `getItem` and `setItem`, its not an associative array itself – Tarang Feb 24 '13 at 12:24
  • I did some experimenting with getItem and setItem and get the behaviour that when the page is first refreshed it correctly finds the local storage, if I open the dialog and change the values it no longer recognises them and reverts to trying to use the forms normal behaviour – ubiQ Feb 24 '13 at 12:48

1 Answers1

0

Take a look at this jsFiddle example: http://jsfiddle.net/Gajotres/J9NTr/, I made it for my other ARTICLE, or it can be found HERE.

Basically localStorage data can be added/modified at any time.

Try to access them like this, this example works on desktop browsers, android and iOS devices.

localStorage.firstname="Dragan";
localStorage.lastname="Gaic";  
Community
  • 1
  • 1
Gajotres
  • 57,309
  • 16
  • 102
  • 130