0

I want if its possible removing all cookies from a local website. I have next code:

 function eraseCookie(c_name) {
    setCookie(c_name,"",-1);
 }

 function getAllCookies(){
    var pairs = document.cookie.split(";");
    var cookies = {};
    for (var i=0; i<pairs.length; i++){
        var pair = pairs[i].split("=");
        cookies[pair[0]] = unescape(pair[1]);
    }
    return cookies;
 }

 var cookies = getAllCookies();
    for(var cookie in cookies) {
        eraseCookie(cookie);
 }

But all cookies appears on the browser. It posible remove cookies with this way?Thanks!

  • 1
    Possible duplicate of [Clearing all cookies with JavaScript](http://stackoverflow.com/questions/179355/clearing-all-cookies-with-javascript) – Al.G. Oct 22 '15 at 09:28
  • It's **not** possible to remove all cookies from a local website. JS will not have access to `httpOnly` cookies. The only way is that you remove them manually - F12 in your browser and find how it handles cookies in the console and then delete. – Mjh Oct 22 '15 at 09:29
  • There could be a possible duplicate [here](http://stackoverflow.com/questions/3400759/how-can-i-list-all-cookies-for-the-current-page-with-javascript). For deleting, check [this](http://stackoverflow.com/questions/595228/how-can-i-delete-all-cookies-with-javascript?rq=1) – Alex.U Oct 22 '15 at 09:37
  • Thanks everyone for the responses. It works like I need now. – Jaime Menendez Llana Oct 22 '15 at 10:53

0 Answers0