CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   Resolved localStorage/sessionStorage question (http://www.codingforums.com/showthread.php?t=288350)

WolfShade 02-26-2013 09:19 PM

localStorage/sessionStorage question
 
Hello, everyone.

I'm learning localStorage and sessionStorage, but I have a question that I have not found via Google, yet.

Local vs. Server: I've tested localStorage in IE8 and FireFox 12 in HTML documents stored on a development server, and it's working.. excellently.

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,

felgall 02-26-2013 09:39 PM

Quote:

Originally Posted by WolfShade (Post 1316173)
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).

rnd me 02-26-2013 10:07 PM

there's no localStorage for local files in IE. or localhost for firefox, or whatever...

felgall 02-27-2013 01:18 AM

Quote:

Originally Posted by rnd me (Post 1316185)
localhost for firefox, or whatever...

Not sure I understand what you untended that part to mean. I have all browsers on my computer including firefox use localhost as the browser home page. All the testing I do both of JavaScript and server side scripts is done using copies of the page that are inside the folder where my browser home page is stored. Once I know they work properly there I then upload them to the web. I have never had a situation where JavaScript that I have tested there across the various browsers has ever worked differently after I uploaded it to my web site.

rnd me 02-27-2013 02:05 AM

[QUOTE=felgall;1316226]Not sure I understand what you untended that part to mean.
there's no localStorage for local files in IE.
there's no localStorage for localhost for firefox.

luckily, 127.0.0.1 has localStrorage in FF.

WolfShade 02-27-2013 01:54 PM

Quote:

Originally Posted by felgall (Post 1316178)
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).

I just double-clicked the .htm file on the Desktop. Hadn't taken the domain into account.

Opening the .htm using localhost:8500/test.htm - localStorage works!

Thanks, felgall!


All times are GMT +1. The time now is 02:18 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.