Clearing all cookies with JavaScript

后端 未结 18 1016
别那么骄傲
别那么骄傲 2020-11-22 05:55

How do you delete all the cookies for the current domain using JavaScript?

18条回答
  •  感情败类
    2020-11-22 06:18

    //Delete all cookies
    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:01 GMT;' +
                'path=' + '/;' +
                'domain=' + window.location.host + ';' +
                'secure=;';
        }
    }
    

提交回复
热议问题