简体   繁体   English

HTML5本地存储和Chrome

[英]HTML5 local storage and Chrome

I am looking to build a offline application. 我正在寻找一个离线应用程序。 I would like to know how clearing of cache works in Google Chrome. 我想知道如何清除Google Chrome中的缓存。 If the user deletes his cookies, would his offline content disappear as well? 如果用户删除他的cookie,他的脱机内容也会消失吗?

I am running Chrome v 5.0.370. 我正在运行Chrome v 5.0.370。 When I perform the "Delete cookies and other site data" from the "Clear Browsing Data" dialog, localStorage is in fact wiped out. 当我从“清除浏览数据”对话框中执行“删除cookie和其他站点数据”时,localStorage实际上被清除了。

Now, to be literal, if the user fires up Webkit Inspector, opens the Storage tab, and only deletes cookies, then localStorage will not be affected. 现在,从字面上看,如果用户启动Webkit Inspector,打开“存储”选项卡,并且删除cookie,那么localStorage将不会受到影响。

But I assume you mean through the normal dialog. 但是我认为您的意思是通过正常对话。

In chrome 19 now. 现在是chrome 19。 I ran ccleaner yest, but my webStorage data was still persistent (atleast for my chrome extension). 我运行了ccleaner yest,但是我的webStorage数据仍然是持久的(对于我的chrome扩展名至少)。

Yes We can store variable declare on local storage like session variable. 是的,我们可以像会话变量一样在本地存储上存储变量声明。 and you can use for future use. 您可以将来使用。

See 看到

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();
};

i will give you example see more: 我会给你的例子看更多:

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

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

The sessionStorage object is most useful for hanging on to temporary data that should be saved and restored if the browser is accidentally refreshed. 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);
 });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM