0

I'm working on a javascript-driven tool that will store a user's selections locally and then repopulate when the page is next navigated to. It's working fine in Chrome but not at all in IE8 or Safari.

I've tried to store this information in cookies using standard javascript, and using the jquery.cookie.js plugin, and also more recently I've tried using local storage instead. I'm storing a lump of XML, so my theory was that perhaps it's too large to store in a cookie, but there's no way it's too large for local storage.

I'm testing this on my local IIS under localhost. Can anyone think of any reason why the other browsers aren't working? I'm finding it strange that it affects both cookies and local storage. I can only think it's some kind of a security setting that's restricting any kind of local storage, cookie or otherwise.

I've played around with settings in IE, settings in IIS, but can't work it out. Any thoughts or ideas would be most welcome!

Regards,

Matt

Matt Winward
  • 1,255
  • 2
  • 15
  • 43
  • If you want answers, you first have to pre-pay with details. What is your code? In what way are 'other browsers' 'not working'? What are the 'other browsers', on what OS, what versions? – Phrogz Feb 09 '11 at 19:54
  • Quick update. I've found that the XML is actually being stored and returned. It's actually a problem with traversing the XML in IE8! For some reason it has a problem with this javascript, but Chrome doesn't: $(xml).find("Action").each(function() { alert('x'); }); – Matt Winward Feb 10 '11 at 07:42

2 Answers2

1

Is the XML in a string, or is it in an object like a DOM reference? I believe IE8's localStorage can only take strings as keys AND values...or primative values that can be automatically cast to string...so you'll have to stringify the object.

If you're worried about size constraints in IE8, check the value of localStorage.remainingSpace (IE-specific property).

I'm not sure why Safari isn't working for you if it works in Chrome. Maybe it can only take strings too.

DaveS
  • 3,156
  • 1
  • 21
  • 31
  • Although I'm storing the XML in a var as an object that I can traverse using jQuery, when I save it, I turn it into an XML string. I was wondering if perhaps it was the XML that's causing the problem, because it turns out if I use local storage with a number, it works fine. I'm going to try HTML encoding the XML to see if this makes a difference. I doubt size limits can have anything to do with it, as the XML is only small (around 1kb). – Matt Winward Feb 10 '11 at 07:12
  • Since you're using jQuery, give this plugin I wrote a try: https://sites.google.com/site/daveschindler/jquery-html5-storage-plugin. It tries to use localStorage, but falls back on cookies if it isn't supported. – DaveS Feb 10 '11 at 21:49
  • 1
    I didn't see your comment about the jQuery .find() method...It sounds like the same problem as http://stackoverflow.com/questions/2815673/why-is-ie8-on-xp-not-properly-reading-from-xml-using-jquery. Take a look at the accepted solution there. – DaveS Feb 10 '11 at 22:02
  • You were right, Dave. I'd already arrived at the same article before reading your comment. I needed to property parse the XML, but differently depending on the browser. Thanks for your help - I'll go try your plugin now! – Matt Winward Feb 12 '11 at 10:05
  • Dave, in trying your plugin i've discovered that to store something from a variable, i have to add empty quotes and a plus before the variable: `$.Storage.set("whichp", ""+myindex)` why can't i just put the variable, like this: `$.Storage.set("whichp", myindex)` ? – android.nick Mar 16 '11 at 06:26
  • It was written that way because Internet Explorer can't store anything except strings...so instead of converting to string without you knowing, I decided to leave it that way, and make you do the conversion so that what you put in is the same type as what you get out (string). – DaveS Mar 20 '11 at 15:48
0

how are you saving the data? If it works in Chrome, Im surprised that it is not working in Safari. use the developer tools to see what is in your localstorage. Use firebug in firefox.

In other words, figure out where it is failing first.

hvgotcodes
  • 118,147
  • 33
  • 203
  • 236
  • 1
    Yeah, I've decided to go back to basics and try to work out at what point it's failing. I just created a very simple test page (http://theprogressbar.co.uk/test.html) that actually does work in my IE8, so I'm now wondering if it's more about what I'm storing. Next I'll try expanding on the test page and bringing it closer to the problem code. – Matt Winward Feb 09 '11 at 20:06