It fails when trying to add to localStorage the following deflated value:
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:
Any ideas why that would be? Nothing in that string seems odd. It does work for some other strings I've done.
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:
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:
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.Code:
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.
Gotta love browser compatibility.
Would it hurt any to call escape() and unescape() for all browsers?
Thanks for finding this also.
I think I'll try it with escape() and unescape() for all browsers. Should still get some good compression savings, but it will make the code more manageable. Today it's IE that doesn't work, tomorrow it's something else. This compression is already way more savings than the plain data so it's a win/win I think.
The one thing I hate about web programming are these browser specific things. Drives me nuts (can you tell I'm new to this :) )
Library updated on front page:
- Put library in .js inside zip file on first post
- Added rnd_me's compression code to save space
- Added Delete() function. Parameters are similar to the Query() function. First parameter is the table name, second parameter is a function. The function should return true on the records to be deleted.
- Added Delete() function example to first post