Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-26-2013, 09:19 PM   PM User | #1
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 950
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
Question 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,
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

Last edited by WolfShade; 02-27-2013 at 04:57 PM..
WolfShade is offline   Reply With Quote
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)
Old 02-26-2013, 10:07 PM   PM User | #3
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,468
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
there's no localStorage for local files in IE. or localhost for firefox, or whatever...
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 02-27-2013, 01:18 AM   PM User | #4
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 rnd me View Post
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.
__________________
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
Old 02-27-2013, 02:05 AM   PM User | #5
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,468
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
[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.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Old 02-27-2013, 01:54 PM   PM User | #6
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 950
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
Quote:
Originally Posted by felgall View Post
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!
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Reply

Bookmarks

Tags
local vs server, localstorage, sessionstorage

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:46 AM.


Advertisement
Log in to turn off these ads.