www.webdeveloper.com
Results 1 to 9 of 9

Thread: LocalStorage Doesn't Work on IE10

  1. #1
    Join Date
    Jun 2005
    Posts
    20

    LocalStorage Doesn't Work on IE10

    I can't get LocalStorage to work on Internet Explorer 10.

    The following test code (from http://www.w3schools.com/html/html5_webstorage.asp) works on Chrome and Safari.

    Code:
    <!DOCTYPE html>
    <html>
    <body>
    
    <div id="result"></div>
    <script>
    if(typeof(Storage)!=="undefined")
      {
      localStorage.lastname="Smith";
      document.getElementById("result").innerHTML="Last name: " + localStorage.lastname;
      }
    else
      {
      document.getElementById("result").innerHTML="Sorry, your browser does not support web storage...";
      }
    </script>
    
    </body>
    </html>
    When I try it on IE10 I get the following error:

    SCRIPT5007: Unable to set property 'lastname' of undefined or null reference


    The code first checks for browser support which IE10 shows positive.

    I've tried windows.localStorage and document.localStorage without any luck.
    In Options/Advanced menu, Enable local DOM storage is checked.

    Any other tweaking I need to do to get it to work?

    Thanks,

  2. #2
    Join Date
    Apr 2013
    Location
    Bournemouth, UK
    Posts
    15
    Are you using <!doctype html> ?

  3. #3
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    window.Storage indicates browser support but not necessarily that it will work under the current protocol. It wont under file:// protocol.

    You could test window.localStorage
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  4. #4
    Join Date
    Mar 2009
    Posts
    493
    Have you tried using the getter/setter functions? Does that work?

    As in :

    Code:
    var x = localStorage.getItem(key);
    localStorage.setItem(key, data);

  5. #5
    Join Date
    Jun 2005
    Posts
    20
    Thanks for replies.

    sQ1rr - Yes, I am using <!doctype html>

    Logic Ali - It would seem you're right regarding file:// protocol. I can get the code to work if I download the page from my server. But it won't work from my local drive. Safari and Chrome work either way. Do you know of any way to get IE10 working from local drive?
    I'd already tried window.localStorage. windows.localStorage was a typo.
    I tried placing everything in a function and using return but I still got the same error.

    Tcobb - I tried the get and set functions but they bring up similar errors.

    The problem seems to be that IE10 doesn't like using localStorage with a webpage on a local drive. Anyone know of a work around would be great.

    Thanks,

  6. #6
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by TedN View Post

    Logic Ali - It would seem you're right regarding file:// protocol. I can get the code to work if I download the page from my server. But it won't work from my local drive. Safari and Chrome work either way. Do you know of any way to get IE10 working from local drive?
    Install a local server like Apache or IIs


    I'd already tried window.localStorage. windows.localStorage was a typo.
    I tried placing everything in a function and using return but I still got the same error.
    Under file:// protocol this does not produce an error on I.E.
    Code:
    <!DOCTYPE html>
    <html>
    <body>
    
    <div id="result"></div>
    <script>
    
    var outputElem = document.getElementById("result");
    
    if( typeof( window.localStorage) !== "undefined" )
    {
      localStorage.setItem( 'lastname', "Smith" );
      outputElem.innerHTML="Last name: " + localStorage.lastname;
    }
    else
    {
      outputElem.innerHTML="Sorry, your browser does not support web storage...";
    }
    
    </script>
    
    </body>
    </html>
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  7. #7
    Join Date
    Jun 2005
    Posts
    20
    Lol.

    I copied your above script and now I get the message, "Sorry, your browser does not support web storage..."

    However, I had also reset ie10 to default values so that might be a problem. Luckily my need is such that I can be browser specific, so I don't have to use IE. I'll play around with this a bit more but if I don't have any luck I'll use Chrome or Safari.

    Incidentally, you mentioned earlier that local storage wouldn't work on file:// protocol. So how would the above code work?

    Thanks,

  8. #8
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by TedN View Post
    Lol.

    I copied your above script and now I get the message, "Sorry, your browser does not support web storage..."

    However, I had also reset ie10 to default values so that might be a problem. Luckily my need is such that I can be browser specific, so I don't have to use IE. I'll play around with this a bit more but if I don't have any luck I'll use Chrome or Safari.

    Incidentally, you mentioned earlier that local storage wouldn't work on file:// protocol. So how would the above code work?

    Thanks,
    It won't make localStorage work locally, it will just tell you that it doesn't. As I indicated previously, if you want to test localStorage routines locally you must install a server.
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  9. #9
    Join Date
    Jun 2005
    Posts
    20
    OK Logic Ali. I see what you're saying, and why I got the message.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles