localStorage.setItem not persisting on refresh

后端 未结 1 1123
我寻月下人不归
我寻月下人不归 2020-12-17 18:20

I\'m trying to do a mega-simple setItem and getItem using HTML5 local storage. It just doesn\'t seem to work though. This works:

$(document).ready(function         


        
相关标签:
1条回答
  • 2020-12-17 18:39

    Okay, after a lot of frustration I have the solution. Basically, I was running this locally just from the filesystem as a 'quick' proof of concept. It didn't work in Firefox nor in IE9 but it did work in Chrome.

    What I ended up doing was trying this on a real domain, and that seems to have done the trick.

    So the conclusion I can draw is that localStorage in Firefox (6.0.2 at least) and IE9 does not work when run on a file-system path. It does in Chrome. Firefox and IE9 require a 'proper' domain to run from, presumably because they are more strict than Chrome in the way they associate the localStorate object to a 'domain' (in Chrome it doesn't need to be a domain as such).

    I hope this has helped people as it's frustrated the hell out of me! :)

    0 讨论(0)
提交回复
热议问题