问题描述
我正在创建2个 HTML
文件,这些文件将在本地存储在iPhone中并通过 WebView
进行访问。 / p>
我想知道是否可以在一个文件中设置 localStorage
,并从中获取存储结果其他文件。
我知道可以从同一域上的文件访问 localStorage
但是,看来你好了无法从不同的本地文件中获取值?
我还尝试在桌面上使用本地文件在Safari中运行此操作,并出现同样的问题。
在本地打开文件时,即使用 file://
协议,截至目前,浏览器无法确定什么是相同域,因此每个文件都被视为一个单独的域。因此,当您打开文件时,您无法使用 localStorage
。
以下是有关此问题的更多信息在FireFox中:。就个人而言,我在这个主题上找不到很多关于Safari的信息。
你也可以看一下:。它可能对您的情况有所帮助。
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.
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.
这篇关于localStorage从本地文件访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!