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

后端 未结 8 1467
日久生厌
日久生厌 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:13
    var x = document.cookie; 
    window.alert(x);
    

    This displays every cookie the current site has access to. If you for example have created two cookies "username=Frankenstein" and "username=Dracula", these two lines of code will display "username=Frankenstein; username=Dracula". However, information such as expiry date will not be shown.

    0 讨论(0)
  • 2020-12-13 02:18

    For just quickly viewing the cookies on any particular page, I keep a favorites-bar "Cookies" shortcut with the URL set to:

    javascript:window.alert(document.cookie.split(';').join(';\r\n'));
    
    0 讨论(0)
提交回复
热议问题