Go Back   CodingForums.com > :: Client side development > JavaScript programming > Post a JavaScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-28-2012, 06:05 PM   PM User | #16
RickP
New Coder

 
Join Date: Nov 2012
Posts: 26
Thanks: 1
Thanked 0 Times in 0 Posts
RickP is an unknown quantity at this point
It worked.

Last edited by RickP; 11-28-2012 at 06:51 PM..
RickP is offline   Reply With Quote
Old 11-28-2012, 06:51 PM   PM User | #17
RickP
New Coder

 
Join Date: Nov 2012
Posts: 26
Thanks: 1
Thanked 0 Times in 0 Posts
RickP is an unknown quantity at this point
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.
RickP is offline   Reply With Quote
Old 11-28-2012, 08:23 PM   PM User | #18
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,455
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by RickP View Post
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.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%

Last edited by rnd me; 11-28-2012 at 08:28 PM..
rnd me is offline   Reply With Quote
Old 11-28-2012, 08:44 PM   PM User | #19
RickP
New Coder

 
Join Date: Nov 2012
Posts: 26
Thanks: 1
Thanked 0 Times in 0 Posts
RickP is an unknown quantity at this point
Gotta love browser compatibility.

Would it hurt any to call escape() and unescape() for all browsers?


Thanks for finding this also.
RickP is offline   Reply With Quote
Old 11-28-2012, 10:29 PM   PM User | #20
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,455
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by RickP View Post
Would it hurt any to call escape() and unescape() for all browsers?
won't hurt, its just a waste of space...
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 11-28-2012, 10:51 PM   PM User | #21
RickP
New Coder

 
Join Date: Nov 2012
Posts: 26
Thanks: 1
Thanked 0 Times in 0 Posts
RickP is an unknown quantity at this point
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 )
RickP is offline   Reply With Quote
Old 11-29-2012, 04:45 AM   PM User | #22
RickP
New Coder

 
Join Date: Nov 2012
Posts: 26
Thanks: 1
Thanked 0 Times in 0 Posts
RickP is an unknown quantity at this point
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

Last edited by RickP; 11-29-2012 at 04:56 AM..
RickP is offline   Reply With Quote
Reply

Bookmarks

Tags
javascript, local, storage

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:30 PM.


Advertisement
Log in to turn off these ads.