3

I am creating a completely offline HTML5 app using localStorage.

I have successfully saved and retrieved and manipulated localStorage data in a single .HTML file. Anyhow, now when I am trying to access localSotrage data stored by one .HTML file on another .HTML file, I am getting no success.

Anyhow, I have created a separate .html file to clear all the localStorage, and that one is working fine.

Is it because localStorage of each web page is separate and cannot be put together or some other error?

  • possible duplicate of [In HTML5, is the localStorage object isolated per page/domain?](http://stackoverflow.com/questions/4201239/in-html5-is-the-localstorage-object-isolated-per-page-domain) – emre nevayeshirazi Dec 04 '13 at 06:08

1 Answers1

3

localStorage is controlled by same-origin policy Assuming you're using file:// it varies by browser:

Webkit:

All file:// documents have the same origin https://bugs.webkit.org/show_bug.cgi?id=20701

Mozilla:

In Gecko 1.8 or earlier, any two file: URIs are considered to be same-origin. In other words, any HTML file on your local disk can read any other file on your local disk.

Starting in Gecko 1.9, files are allowed to read only certain other files. Specifically, a file can read another file only if the parent directory of the originating file is an ancestor directory of the target file. Directories cannot be loaded this way, however.

https://developer.mozilla.org/en-US/docs/Same-origin_policy_for_file:_URIs

IE:

Doesnt apply (see: localStorage object is undefined in IE)

Community
  • 1
  • 1
arcyqwerty
  • 8,893
  • 2
  • 40
  • 77