Html LocalStorage 不适用于 iPad 和 iPhone

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12630396/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 03:04:02  来源:igfitidea点击:

LocalStorage not working on iPad and iPhone

iphoneiosipadhtmllocal-storage

提问by lmttag

I'm having troubles with HTML5 LocalStorage on my iPad and iPhone. I've developed a HTML5/CSS3/JavaScript (jQuery/jQuery Mobile) website and I'm trying to store a couple of pieces of data to LocalStorage (just a couple of small strings).

我在 iPad 和 iPhone 上使用 HTML5 LocalStorage 时遇到问题。我开发了一个 HTML5/CSS3/JavaScript (jQuery/jQuery Mobile) 网站,我正在尝试将一些数据存储到 LocalStorage(只是几个小字符串)。

When I navigate to the website on either the iPad or the iPhone by simply opening Safari and typing in the URL, I get notification from Moderizr that localstorage is not supported, and, thus, my values are not saved on the device.

当我通过简单地打开 Safari 并输入 URL 导航到 iPad 或 iPhone 上的网站时,我收到来自 Moderizr 的通知,不支持本地存储,因此,我的值没有保存在设备上。

However, if I use the Save to Home Screen option, save an icon/link to my mobile website on the Home Screen, close "regular" Safari, and open the application using the Home Screen icon, Moderizr tells me localstorage is available, and my values are written and read as expected.

但是,如果我使用“保存到主屏幕”选项,在主屏幕上保存到我的移动网站的图标/链接,关闭“常规”Safari,然后使用主屏幕图标打开应用程序,Moderizr 会告诉我本地存储可用,并且我的值按预期写入和读取。

So, I'm confused. Why does it work after saving the link to the Home Screen but it doesn't work if I type the URL directly in Safari? Is there some trick I'm missing to make it work in both scenarios?

所以,我很困惑。为什么在将链接保存到主屏幕后它可以工作,但如果我直接在 Safari 中输入 URL 则它不起作用?是否有一些技巧可以让它在两种情况下都能正常工作?

I've tried with both iOS 5.1.1 and 6. And, my settings are the basic defaults.

我已经尝试过 iOS 5.1.1 和 6。而且,我的设置是基本默认值。

Thanks.

谢谢。

回答by lmttag

After many headaches, I think I got it figured out. HTML5 local storage and private browsing do not mix. I had private browsing on (in the Safari settings) and that appeared to be blocking local storage. Actually, an exception was being thrown but swallowed up by the browser (???). Once I turned private browsing off, everything appeared to work.

经过多次头痛,我想我明白了。HTML5 本地存储和隐私浏览不可混用。我进行了隐私浏览(在 Safari 设置中),这似乎阻止了本地存储。实际上,一个异常被抛出但被浏览器吞没了(???)。一旦我关闭隐私浏览,一切似乎都正常了。