Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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.

— asked May 21st 2010 by Alan McConnell
  • cookies
  • iphone
  • webview
0 Comments

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";");
    
    — answered November 17th 2010 by Aaron Saunders
    permalink
    1 Comment
    • Thanks for your answer.
      And do you have any trick to set the cookies before the page is loaded (so the page is loaded with the cookies we previously manually set)?

      — commented February 14th 2011 by Thomas Dall'Agnese
  • you can like this

    Ti.Network.createHTTPClient().clearCookies(&#39;https:&#x2F;&#x2F;url_to_clear_cookies_for&#39;);

    even if using webView.
    it will works

    — answered August 12th 2013 by Daehyeon Shin
    permalink
    0 Comments
  • 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.

    — answered May 21st 2010 by Dan Tamas
    permalink
    1 Comment
    • Entra gratis a las mejores discotecas de Madrid http://www.midnightvip.com

      — commented June 14th 2013 by a a
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.