View Single Post
Old 02-26-2013, 09:39 PM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,465
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by WolfShade View Post
However, I tried testing with a .htm document that I created (via NotePad) on my Desktop, and it's not working.. at all.

For localStorage, is location going to determine if it's going to work? Will it not work, if it's on the same machine from which I am testing?

Thank you,
How are you accessing the local file? I would expect that if you are running a local server and access the page via http://localhost that it should work exactly the same on your computer as it does if uploaded to a remote server.

There are a growing number of things in JavaScript that behave differently if the script is running via a web server (whether local or remote) to how it runs if you try to just access the file locally. Some browsers eg. IE will not allow any JavaScript at all to be run outside of a server unless you specifically allow it each time you want to run it and then it may not run the same as it would on a server.


While it is obvious that cookies will not work if you try to run the page directly without a web server as the cookies get passed to and from the server it isn't as obvious why localStorage should have the same restriction except that the security is supposed to work based on the domain name and pages run directly don't have a domain name (which is one possibility as to why it doesn't work outside a server).
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Users who have thanked felgall for this post:
WolfShade (02-27-2013)