I'm using javascript to remove a cookie but for some reason it isn't working with Chrome. The script I'm using is;
function clearCookie()
{
document.cookie = 'myCookie=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/myPath/';
}
This works on;
..but doesn't work on Chrome 7.0.517.44, after the cookie is supposed to be cleared I can still see it and the value hasn't changed.
Any ideas? Are there any user settings in Chrome that might prevent my cookie from being removed?
Moreover, if you try to remove the Google services cookies, the browser will automatically re-create them, making it impossible to remove data stored on Google servers. Thankfully, you can fix it by logging out of the Google services and then clearing out the browser history.
You can use setCookie('name', 'value', 0) to delete a cookie.
JavaScript can also manipulate cookies using the cookie property of the Document object. JavaScript can read, create, modify, and delete the cookies that apply to the current web page.
Chrome doesn't support cookies on file:// and localhost uris. See this so question - Why does Chrome ignore local jQuery cookies?
You need to use the right datetime format for it to work. The following should do the trick
function clearCookie()
{
document.cookie = 'myCookie=; expires='+new Date(0).toUTCString() +'; path=/myPath/';
}
And of course you need to specify the exact same path and&or domain specified on cookie creation.
You can clear a cookie in chrome, but you need to set the domain as well when creating the blank cookie to replace the current one.
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