• Resolved petersonsilva

    (@petersonsilva)


    Hi guys,

    The password-protected pages and posts have a, hm, feature that I wanted to disable. When somebody puts the password in, sees the page, closes the browser and walks away (and the browser is not set to forget cookies right away), anyone can see the password-protected page, because the cookie is still there. So I was wondering: how can I make a link so the person can click on it and have his/her cookies erased automatically? I tried inputting this bookmarklet javascript…

    javascript:(function(){C=document.cookie.split(";%20");for(d="."+location.host;d;d=(""+d).substr(1).match(/\..*$/))for(sl=0;sl<2;++sl)for(p="/"+location.pathname;p;p=p.substring(0,p.lastIndexOf('/')))for(i%20in%20C)if(c=C[i]){document.cookie=c+";%20domain="+d.slice(sl)+";%20path="+p.slice(1)+"/"+";%20expires="+new%20Date((new%20Date).getTime()-1e11).toGMTString()}})()

    … code into html, but this hasn’t worked out. If you have any ideas, I’d appreciate it very much, I honestly don’t know what’s wrong with the method.

    Thanks in advance!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter petersonsilva

    (@petersonsilva)

    I got it!!

    I included a script on the header. Inside the script there is:

    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";
        }
    }

    After that, I just created a link like this:

    Foo

    Thread Starter petersonsilva

    (@petersonsilva)

    Ok, the code turned into an actual link.

    It was:

    <a href="https://foo.bar" OnClick="deleteAllCookies();">Leave</a>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Deleting Cookies’ is closed to new replies.