iPhone Safari上的HTML5 - localStorage存储的数据并不总是持久存在。为什么? [英] HTML5 on iPhone Safari - data stored by localStorage does not always persist. Why?

查看:102
本文介绍了iPhone Safari上的HTML5 - localStorage存储的数据并不总是持久存在。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用HTML5的localStorage编写一个简单的iPhone网络应用程序。

在2G设备上进行的测试表明,尽管打开的Safari窗口被记住,但Safari进程被杀后,使用localStorage存储的数据仍然无法保留。

I write a simple iPhone web app using HTML5's localStorage.
Tests on a 2G device show that data stored using localStorage does not persist after the Safari process is killed although the opened Safari windows are remembered.

如果我在不同的Safari窗口的不同站点上,数据也会丢失,然后我将窗口更改为主题中的Web应用程序显示的位置。当Safari加载页面时,它会自动刷新页面。然后数据丢失。
这是一个简单的测试代码:

The data is also lost in a case where I am on a different site on a different Safari window, then I change the window to where the web app in subject is shown. When Safari loads the page it automatically refreshes the page. Then the data is lost. This is a simple test code:

<html>
<head>
    <meta name="viewport" content="height=device-height, width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
</head>
<body>
<script>
    alert("1:" + localStorage.getItem("test"));
    localStorage.setItem("test", "123");
    alert("2:" + localStorage.getItem("test"));
</script>
</body>

据我所知数据应该持续下去!

任何人都可以对这种行为有所了解吗?我该怎么做才能让持久性发挥作用?

As far as I understand the data should persist!
Can anyone shed some light on this behavior? What should I do to get the persistence to work?

谢谢!

汤姆。

Thanks!
Tom.

推荐答案

根据Apple( https://developer.apple.com/library/content/documentation/iPhone/Conceptual/SafariJSDatabaseGuide/Name-ValueStorage/Name-ValueStorage.html#//apple_ref/doc / uid / TP40007256-CH6-SW3 ),在Safari 4.0中添加了localStorage支持。

According to Apple (https://developer.apple.com/library/content/documentation/iPhone/Conceptual/SafariJSDatabaseGuide/Name-ValueStorage/Name-ValueStorage.html#//apple_ref/doc/uid/TP40007256-CH6-SW3), localStorage support was added in Safari 4.0.

根据维基百科( https:// en .wikipedia.org / wiki / Safari_version_history ),在iPhone OS 3.0中添加了Safari 4.0。

According to Wikipedia (https://en.wikipedia.org/wiki/Safari_version_history), Safari 4.0 was added in iPhone OS 3.0.

2G iPhone未预装OS 3.0或更高版本。您的iPhone OS版本很可能太旧了。

2G iPhones did not come with OS 3.0 or later pre-installed. Your iPhone OS version is most likely too old.

这篇关于iPhone Safari上的HTML5 - localStorage存储的数据并不总是持久存在。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆