Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Highlighted
Developer
Posts: 237
Registered: ‎11-24-2012
My Device: Blackberry 10 Dev Alpha
My Carrier: Telkomsel
Accepted Solution

How Clear Cookies WebView

Hi, I want to clear cookies on WebView.

What I'm tryin to do is something like logout user and then login again with another userId. And I need to clear cookies.

 

I'm try like this but cookies not clear.

 

            WebView {
id: myWebView url: "http://www.google.com/search?q=" + mySearchTerm.text

onCreationCompleted: {
storage.clear();
storage.clearCookies();
} } // end WebView


function clear() {
myWebView.storage.clear();
}

 

Also try make own clear, and call this before navigate to this page (with WebView), but also cookies not clear

 

 

How to do this?
Maybe I'm wrong on implement this..

 

 

Please help,

Thanks

Developer
Posts: 133
Registered: ‎05-10-2013
My Device: Blackberry Z10
My Carrier: -

Re: How Clear Cookies WebView

For one, storage.clear() should also clearCookies(), but it's good to be safe. Remove your own clear() function as well. Now, since your code seems fine, try

 

A) changing the text of a label or some other property which is more visual to you, just to see if onCreatinComplete() is being called, or

 

B) move storage.clear() to another function (like an onTouch), to see if the cache can be cleared with that exact call.

 

Come back here with your results.

----------------------------------------
Remember to mark the thread as solved at the post that solved your problem, and if you like a post, like it!
Retired
Posts: 83
Registered: ‎10-10-2012
My Device: Z30
My Carrier: Bell

Re: How Clear Cookies WebView

Follow DrShivago's advice.

For some more info, please give this page a quick read:

 

https://developer.blackberry.com/cascades/reference/bb__cascades__webstorage.html

 

Please let me know if the above was useful.

 

-g

 

Developer
Posts: 237
Registered: ‎11-24-2012
My Device: Blackberry 10 Dev Alpha
My Carrier: Telkomsel

Re: How Clear Cookies WebView

[ Edited ]

Hi, I'm now can clear the cookies.

 

But it kind weird.

I'm clearing the cookies when leaves (nav back) from WebView pages -> success

 

If I'm clearing cookies when enter the pages -> not work

 

The example is here:

https://developer.blackberry.com/cascades/documentation/ui/webview/loadingwebcontent.html

There is example with two pages, I'm just try to add clear cookies on the webview.

 

 

Thanks

Developer
Posts: 133
Registered: ‎05-10-2013
My Device: Blackberry Z10
My Carrier: -

Re: How Clear Cookies WebView

Simply put, you can't empty the cache or delete any cookies when accessing a WebView for the same reason you can't delete then on your computer when the browser is open. If the WebView is accessing any persistent cookies in the cache, and you remove them, errors could occur, and so your system prefers to do it when nothing is being accessed.

 

I'm guessing what's happening is when you enter the page, the WebView gets access to the cookie folder and denies any calls to clear(), clearCookies() or clearCache(). Someone feel free to correct me on this if my explanation is off.

----------------------------------------
Remember to mark the thread as solved at the post that solved your problem, and if you like a post, like it!
Developer
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

Re: How Clear Cookies WebView

The cookie object in webview isnt initialized until after the page has finished its push transition to the screen and its rendered (maybe not that exactly but theres some async issue here). To get around it you should try setting the url after you set the cookies, possibly in the creation complete slot or somewhere else after it has rendered.
Like all of my posts