3

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?

Wayne Hartman
  • 18,369
  • 7
  • 84
  • 116

2 Answers2

4

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.

Lucho Giribone
  • 258
  • 1
  • 7
  • I have never seen this function before. Do you happen to know if it works in all of the latest browsers? I will probably test it here later. – Caimen Jul 14 '11 at 13:43
  • tested and passed in FF5, FF4, FF3.6, Opera 11.5, Chrome 12, IE9, IE8 and Safari 5 ;) – Lucho Giribone Jul 14 '11 at 14:37
3

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.

Caimen
  • 2,623
  • 2
  • 26
  • 43
  • this link is very useful: http://developer.apple.com/library/safari/#codinghowtos/Desktop/DataManagement/_index.html – Jacob Mouka Jul 13 '11 at 18:17