Delete / Disable WebView Cookies?
Anyone know of anyway to clear the cookies for a WebView, or disable them altogether? Trying to create a stateless login pop-up using a WebView and the fact that it's storing login credential cookies is breaking everything.
I believe there's a database with cookie information in it, but it's undocumented.
3 Answers
-
This is code I wrote to get all the cookies from a webView.
var webView = Ti.UI.createWebView({url:"http://www.google.com"}); win1.add(webView); webView.addEventListener('load',function(e) { var cookies = webView.evalJS("document.cookie").split(";"); Ti.API.info( "# of cookies -> " + cookies.length ); for (i = 0; i <= cookies.length - 1; i++) { Ti.API.info( "cookie -> " + cookies[i] ); } });
You could modify it to get the cookie name as it loops through and then delete the cookie like this
webView.evalJS("document.cookie = cookie_name += "=; expires=-1";");
-
you can like this
Ti.Network.createHTTPClient().clearCookies('https://url_to_clear_cookies_for');
even if using webView.
it will works -
You could make a function inside the html of the WebView, that cleans the cookies.
If you need the cleaning to be done only once you could trigger this function with a Titanium event, only when the app starts.