Jake Chasan Jake Chasan - 1 month ago 22
Javascript Question

localStorage access from local file

I am creating 2

HTML
files that will be stored an an iPhone locally and accessed through a
WebView
.

I am wondering if it is possible to set
localStorage
in one file, and get the results of the storage from the other file.

I know that
localStorage
is accessible from files on the same domain, however, it appears that you can not get the value from a different local file?

I have also tried running this in Safari on the desktop with local files and the same issue occurs.

Answer

When you are opening the files locally, i.e. using the file:// protocol, as of now the browsers can not determine what is "same domain" so every file is considered a separate domain. Thus you can not use localStorage when you're opening the files.

Here is some more information on the problem in FireFox: https://bugzilla.mozilla.org/show_bug.cgi?id=507361 . Personally I couldn't find much about Safari on this topic.

You can also look over this: Javascript/HTML Storage Options Under File Protocol (file:\\) . It might be helpful in your situation.

Comments