1

Browsing all the questions/answers here but can't find a resolution to my problem. The condition ('localStorage' in window) returns true but object of localStorage itself remains undefined. <!DOCTYPE html> set properly, can't get it working. I am using IE10. Tried watch it via developer tools, the same result.

Any ideas here?

Edit

function storageAvailable() {
    try {
        return 'localStorage' in window && window['localStorage'] !== null && window['localStorage'] !== undefined;
    } catch (e) {
        return false;
    }
}

Based on the same issue in IE9 I would like to update the question: is there any workaround? I cannot use even static server on the machine I need to test on.

tomasb
  • 1,663
  • 2
  • 22
  • 29
  • 1
    You should post your code, as that's probably where the problem lies :) – Pointy Oct 11 '13 at 22:56
  • The code is irrelevant i think, it is undefined even when just watching expression via IE debugger. But anyway adding my functions which returns false. – tomasb Oct 11 '13 at 22:58
  • What is the url in your browser when you try to run this code? – dezman Oct 11 '13 at 23:02
  • The `try .. catch` here is completely unnecessary. There is nothing that will throw an exception, unless you shadow `window`. – Ingo Bürk Oct 11 '13 at 23:13
  • Ah yes agreed, I just copied this function from some other thread here... originally it was without the last condition: && window['localStorage'] !== undefined; so it was returning true and then i got exceptions ... – tomasb Oct 11 '13 at 23:17

1 Answers1

4

I'm gonna go out on a limb here and say that your problem is that local storage wont work on file:// protocol in ie, so you need some kind of server.

dezman
  • 18,087
  • 10
  • 53
  • 91
  • That would be really unpleasant for the development, it is working in all other browser like opera, ff, safari, chrome ... But I must check that. – tomasb Oct 11 '13 at 23:12
  • 1
    Fortunately these days it's a matter of two minutes to set up a local web server ;) – Ingo Bürk Oct 11 '13 at 23:13
  • In my case, I just right-click any PHP file and choose my custom "Server (local)" menu item. How you go about it is up to you, but it's extremely convenient to have a feature like this. I implemented mine with a batch script. – Niet the Dark Absol Oct 11 '13 at 23:21
  • 1
    [xampp](http://www.apachefriends.org/en/xampp.html) is fairly common. Of course you could also use more simple things like command-line tools. If you need PHP, setting up a stack like xampp is worth the five minutes, though. – Ingo Bürk Oct 11 '13 at 23:21
  • If the problem is local storage on the file protocol, you might want to look at different ways to store your data. http://stackoverflow.com/questions/5914029/javascript-html-storage-options-under-file-protocol-file – Daan van Hulst Feb 28 '14 at 13:03