Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts

    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,
    Last edited by WolfShade; 02-27-2013 at 04:57 PM.
    ^_^

    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".

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,639
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    WolfShade (02-27-2013)

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,333
    Thanks
    11
    Thanked 587 Times in 568 Posts
    there's no localStorage for local files in IE. or localhost for firefox, or whatever...
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,639
    Thanks
    0
    Thanked 649 Times in 639 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,333
    Thanks
    11
    Thanked 587 Times in 568 Posts
    [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 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #6
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    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".


  •  

    Tags for this Thread

    Posting Permissions

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