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=/';
JavaScript can create, read, and delete cookies with the document.
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.
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.
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=/';
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';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With