How to remove HTML5 persistant databases in UIWebV

2019-07-02 03:41发布

问题:

I have a native application that uses a UIWebView and notice that with sites like Google, they are using an HTML5 local database for storing information. I am using native APIs for clearing items out of the cookie store, but clearing the persistent cookie store does nothing to remove these local databases. Is there a way to remove them through a native API?

UPDATE:

Is there a way to do this through a non-native API or javascript?

回答1:

You can run this JavaScript directly in your url bar:

javascript:localStorage.clear();

Note that local storage is same domain scoped, so it will clear the storage of the current domain that you are.

Currently google uses it for google Analytics, adSense, etc.



回答2:

You can remove all localstorage variables by using a function like this.

function clearStorage() {
  for(var i in localStorage)
  {
    localStorage.removeItem(i);
  }
}

Of course if you need to only get rid of certain variables or simply set them to default values types then this will have to be modified. I am not familiar enough with UIWebView or your use case to know which variables you would want removed.



标签: ios uiwebview