简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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