Clearing all cookies with JavaScript

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

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

18条回答
  •  盖世英雄少女心
    2020-11-22 06:28

    An answer influenced by both second answer here and W3Schools

    document.cookie.split(';').forEach(function(c) {
      document.cookie = c.trim().split('=')[0] + '=;' + 'expires=Thu, 01 Jan 1970 00:00:00 UTC;';
    });
    

    Seems to be working

    edit: wow almost exactly the same as Zach's interesting how Stack Overflow put them next to each other.

    edit: nvm that was temporary apparently

提交回复
热议问题