Reputation: 65
I am using this JavaScript Code, but it will return only cookies of a particular page. I want to clean all the cookies of Browser
function deleteAllCookies() {
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
var eqPos = cookie.indexOf("=");
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
}
};
Upvotes: 4
Views: 19473
Reputation: 707148
You cannot delete cookies via Javascript that come from other domains than the page you are currently on. This is a browser security feature. And, if a cookie is marked for a particular path, you can only access it from a page on that particular path (even from the same domain).
And, for cookies that are marked HttpOnly
(e.g. server-side access only cookies), you can't even delete those for your own domain via javascript.
The only way to clear all cookies is for you (the user) to use the browser's user interface to delete the cookies or to configure your browser to automatically clear cookies when you close the browser.
Upvotes: 4