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";
}
};
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";
}
};
Share
Improve this question
asked Mar 2, 2015 at 7:24
Satish SomaniSatish Somani
651 gold badge2 silver badges7 bronze badges
7
- 1 look at this stackoverflow./questions/595228/… – Arunprasanth K V Commented Mar 2, 2015 at 7:25
- i already use that but its also returning same – Satish Somani Commented Mar 2, 2015 at 7:27
- You can only remove cookies created by JavaScript - if a cookie was create by the server, then you cannot remove it through JavaScript.you need to know name, path and domain of a cookie then only you can reliably delete the cookie – Arunprasanth K V Commented Mar 2, 2015 at 7:27
- I want to clean the cookies that is created by facebook and our web application. what is path here.. Domain is facebook. name is name of cookie – Satish Somani Commented Mar 2, 2015 at 7:29
- I think what you are trying to do is accessing cross domain cookie.Which is not possible due to security reason. How ever I will look forward to see the answer of this. – Abhisek Malakar Commented Mar 2, 2015 at 7:37
1 Answer
Reset to default 4You cannot delete cookies via Javascript that e 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.