Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Degrade gracefully in IE on local files #9

Closed
wants to merge 1 commit into from

Conversation

JeroenVu
Copy link

localStorage is not available in Internet Explorer when loading files directly from the filesystem.
This "fix" prevents your whole app to crash. Everything works, but nothing gets saved.

I found a project, called jStorage (http://www.jstorage.info/) that tries to fix this issue.

@gsklee
Copy link
Owner

gsklee commented Aug 27, 2013

I am not sure if this actually fixes anything. I mean, yeah, it no longer crashes, but you still have a malfunctioning Web Storage. In such cases, you might wanna consider using other data persistence solution.

@gsklee gsklee closed this Aug 27, 2013
@JeroenVu
Copy link
Author

Too bad you don't see the added value of not crashing an entire application... I'm using it in my project anyway.

Btw, thanks for your great work on this module!

@gsklee
Copy link
Owner

gsklee commented Aug 27, 2013

Alright - can you do a test for me? Since the fake Web Storage API you provided didn't even include a getItem method, I suspect you only need an empty object to cheat IE9.

Can you modify L43 to var webStorage = $window[storageType] || {}, and see if this prevents the crash?

If not, make it var webStorage = $window[storageType] || {setItem: function() {}, removeItem: function() {}},

Many thanks!

@gsklee gsklee reopened this Aug 27, 2013
@JeroenVu
Copy link
Author

Using an empty object prevents the crash in IE7, IE8, IE9 and IE10 (tested with browser mode in IE10), but it shows an error in the console: SCRIPT438: Object doesn't support property or method 'setItem'.

That's why I added the empty functions. I could have added getItem also, but it will never be called, because i < webStorage.length will always evaluate to false since webStorage.length is undefined.

It might not be the best solution for every project to just silently ignore this problem though. What about logging something meaningful to the console?

@gsklee
Copy link
Owner

gsklee commented Aug 28, 2013

It would be great if you can try catch the error and log a message, yep.

@gsklee
Copy link
Owner

gsklee commented Sep 17, 2013

Just did a test on a real IE8 and the app didn't crash at all; instead there is a TypeError: 'length' is null or not an objectundefined error in the console.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants