Quote:
Originally Posted by RickP
It fails when trying to add to localStorage the following deflated value:
"‹®VÊLQ²:J9‰•©E@”¡£”œ_ZTœ
2jc"
I get "Invalid argument." Note there is a return character there so not sure if that's messing it up.
This came from the string:
"[{"id":"id","player":"player","course":"course"}]"
Any ideas why that would be? Nothing in that string seems odd. It does work for some other strings I've done.
|
ok. i looked into it.
Firstly, "It" doesn't fail, this is an IE localStorage problem, not a string problem or an issue with my functions.
my functions are fine in IE 6+
it seems that IE, even IE10 has an issue with localStorage.
this is a bug with IE's localStoage, not the code i posted, but i'll try to help anyway.
in chrome and firefox, this is true:
localStorage['temp']=unescape("%01");
localStorage['temp']==unescape("%01")
but in IE, it's false (9+10) or throws (7+8)
so, we need to fix IE, and IE only, both the 8 and 9/10 branch. Fun!
this alternate routine works on 8+9+10:
Code:
var code=deflate('[{"id":"id","player":"player","course":"course"}]');
localStorage['_temp']=escape(code);
inflate(unescape(localStorage['_temp']));
you may want to use a custom save(key, value) function instead of just using localStorage[key]=value, so that you have a chance in your normal workflow to handle IE's specific needs. it's also a chance to bake-in a date and other machine-gathered meta about the stored values.
just so there's no confusion to anyone reading this a year from now, one last time; the functions work in IE, localStorage has minor compat issues that require special handling.
why IE can't localStorage all the chars possibilities i don't know, but i appreciate your pointing this out, it's good to know.