开发者

HTML5 local storage and Chrome

I am looking to build a offline application. I would like to know how c开发者_开发知识库learing of cache works in Google Chrome. If the user deletes his cookies, would his offline content disappear as well?


I am running 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.

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.

But I assume you mean through the normal dialog.


In chrome 19 now. I ran ccleaner yest, but my webStorage data was still persistent (atleast for my chrome extension).


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.

// 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);
 });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜