Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript to delete cookie on android web browser

What is the javascript to delete a cookie on android web browser. The usual method of setting an expiration date of the cookie to a date in the past does not work in android web browser.

For e.g. the below code works in desktop web browsers and mobile safari but does not work in android web browser.

document.cookie = 'cookiename=cookievalue; expires=Thu, 2 Aug 2001 20:47:11 UTC; path=/';
like image 974
govin Avatar asked Dec 08 '10 20:12

govin


People also ask

Can JavaScript delete cookies?

JavaScript can create, read, and delete cookies with the document.

Which method is used to delete a cookie?

Deleting Cookie: There is no special dedicated function provided in PHP to delete a cookie. All we have to do is to update the expire-time value of the cookie by setting it to a past time using the setcookie() function. A very simple way of doing this is to deduct a few seconds from the current time.

How do you remove items from cookies?

To delete a cookie, you just need to set the value of the cookie to empty and set the value of expires to a passed date.


2 Answers

I've seen browsers (actually in TV sets, but not sure which it was exactly), that did not accept the 'expires=' field (with an absolute date), but worked well with 'max-age=' (live-time in number of seconds from now). So maybe try to delete the cookie by:

document.cookie = 'cookiename=; max-age=0; path=/';
like image 174
fast Avatar answered Oct 22 '22 13:10

fast


Have you tried also including the domain in the cookie setting line? I remember that in some cases you had to be very explicit with the domain and path matching (or being compatible with) the current document location in order to delete a cookie:

document.cookie='cookiename=cookievalue; path=/; domain=current-domain; expires=Thu, 01 Jan 1970 00:00:01 GMT';
like image 35
cosjav Avatar answered Oct 22 '22 13:10

cosjav