HTML5本地存储和Chrome

5
我想要构建一个离线应用程序。我想知道在Google Chrome中如何清除缓存。如果用户删除了他的cookies,他的离线内容会消失吗?

这个问题让我真的以为它是关于Chrome对HTML5本地存储支持不足的:http://diveintohtml5.info/storage.html - John Magnolia
3个回答

4
我正在使用Chrome v5.0.370。当我从“清除浏览数据”对话框执行“删除Cookie和其他站点数据”时,实际上localStorage也被清除了。
现在,要字面理解,如果用户启动Webkit Inspector,打开Storage选项卡,并且删除cookie,则不会影响localStorage。
但我认为你指的是通过正常对话框进行操作。

对的,localstorage 就像一个更大/更有组织的 cookie 系统,但并不更可靠。 - Mark
2
在前面的评论中补充一点,客户端永远不可靠。 - Matt
是的,随着所有类似于HTML5的本地应用程序炒作和本地存储功能的兴起 - 这真的很糟糕。我知道有很多人有时会使用删除历史记录的功能(即使不使用个人电脑) - 这使得本地存储比cookie更加不可靠... - jack33
这还是现状吗? 使用“删除Cookie和其他站点数据”会删除Chrome的所有本地存储,包括Chrome扩展设置吗? - Damien Golding

2

我现在使用的是Chrome 19版本。昨天我运行了CCleaner,但我的WebStorage数据仍然存在(至少对于我的Chrome扩展程序而言)。


0

是的,我们可以将变量声明存储在本地存储中,就像会话变量一样。您可以将其用于将来的使用。

请参见。

interface Storage {
  readonly attribute unsigned long length;
  [IndexGetter] DOMString key(in unsigned long index);
  [NameGetter] DOMString getItem(in DOMString key);
  [NameSetter] void setItem(in DOMString key, in DOMString data);
  [NameDeleter] void removeItem(in DOMString key);
  void clear();
};

我会给你一个例子,看更多:

// Save data to the current session's store
sessionStorage.setItem("username", "John");

// Access some stored data
alert( "username = " + sessionStorage.getItem("username"));

sessionStorage 对象最有用的是用于保存临时数据,如果浏览器意外刷新,这些数据应该被保存和恢复。

// Get the text field that we're going to track
 var field = document.getElementById("field");

 // See if we have an autosave value
 // (this will only happen if the page is accidentally refreshed)
 if (sessionStorage.getItem("autosave")) {
    // Restore the contents of the text field
    field.value = sessionStorage.getItem("autosave");
 }

 // Listen for changes in the text field
 field.addEventListener("change", function() {
    // And save the results into the session storage object
    sessionStorage.setItem("autosave", field.value);
 });

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接