-
Notifications
You must be signed in to change notification settings - Fork 334
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
Fallback gracefully to using an object in memory to store data when localStorage is undefined #137
Comments
IE9 has a security thing with localStorage. IE9 doesn't allow localStorage locally. Just put it on a server like WAMP or if you're VMing into Windows run Python's simple server ( Are you just developing, or does this need to be run locally for some reason? |
Yes, I need to run locally, this is part of an HTML Application (HTA) - HTA's get special access to the local system but, as you say, some other things don't work. I need to access a bunch of markdown formatted files that will be on the local drive and I wont be able to run up a server due to restrictions in place on the PC's. I've just made a quick amendment that I'm sure breaks all sorts of stuff but seems to work at first sight. I've added the following between loading JQuery and your script file: <script>
var myStorage = [];
if (localStorage) {
myStorage = localStorage;
}
</script> I then did a global search and replace of |
You don't want that, you want: if (!localStorage) { //if it doesn't exist use a backup
localStorage = {}; //override the default localStorage object since it doesn't exist
} This way in Firefox and Chrome it'll be able to store drafts in localStorage, but if it can't (IE9) it'll use a backup. It wont save on refreshes, obviously, but it'll work. Also you wont have to do a find and replace and upgrades will still work. |
I tried that first - sorry I should have said. I got an error saying I wasn't allowed to redefine a constant. So it looks like IE9 knows that it is a reserved word. Actually, you've got me thinking about web servers - I know that Java is available on all of the machines so I'm just looking to see if there is a Java equivalent of the Python suggestion - don't know why I didn't think of that since I'm often forced to use Java tools on these machines because it is the only thing I can actually run beyond what the brain-dead admins think should be run. |
I see, thats good to know. I'll change the title of your post and work on a feature to fallback gracefully in IE9 rather than just dying if run locally. |
@TotallyInformation also, when you're done i'd love a demo of it or a screencast and the source to see what you did with EE :) |
OK, thanks for the help. I've not had much luck with the Java SimpleServer equivalent. As usual, Java proves frustrating. I could create something myself - if I were a Java programmer! |
FYI @TotallyInformation I'm going to implement a way to disable localStorage since I've had a couple people request this off GitHub and recently @levint from ticket #141. I want to get this in develop this week. |
… also makes it so EE wont crash when localStorage is undefined (IE7 and also when IE9 is using the file protocol)
@TotallyInformation Could you pull develop and let me know if the new commit fixes your issue? If localStorage is undefined it writes to an empty object just like you did above. Also, while I was in there I added a boolean I haven't added docs or tests for this yet, but all tests pass. If it breaks anything let me know! |
Added docs and tests, so closing, but feel free to reopen if you are still having problems. |
Hi Oscar, we've been chatting over on Stack Overflow.
I've been trying to get Epic to work in IE9 but I can't do it. Your demo page works fine but I cannot run it locally (e.g. without a server).
Here is the code:
Everything does load and it runs perfectly in Firefox 11. It does not run in IE9. It seems to be something to do with localstorage. The errors are:
Line 1135 is:
Line 1000 is:
In each case, the name is set OK but localStorage seems to be underfined. The problem seems to be at line 346:
Because that first step fails on IE9 when loaded locally. I simply added an alert wrapped in an
else {}
to prove the point.Would it not be better to put out an alert instead of silently failing for reasons unknown?
Of course, it would be even better if something could be done about this. Would it be possible to use a library instead of localStorage?
The text was updated successfully, but these errors were encountered: