How can I list all cookies for the current page with Javascript?

后端 未结 8 1497
日久生厌
日久生厌 2020-12-13 01:34

Is there any way to, with help of Javascript, list all cookies associated with the current page? That is, if I don\'t know the names of the cookies but want to retrieve all

8条回答
  •  忘掉有多难
    2020-12-13 02:01

    You can list cookies for current domain:

    function listCookies() {
        var theCookies = document.cookie.split(';');
        var aString = '';
        for (var i = 1 ; i <= theCookies.length; i++) {
            aString += i + ' ' + theCookies[i-1] + "\n";
        }
        return aString;
    }
    

    But you cannot list cookies for other domains for security reasons

提交回复
热议问题