Cannot delete cookies using javascript

Asked 1 weeks ago, Updated 1 weeks ago, 307 views

I would like to create a bookmarklet that can delete all cookies on the site using javascript.
While checking the browser console,


I was able to check which cookies exist using , but I am having trouble deleting them.

 document.cookie="name=; max-age=0";
document.cookie="name=;expires=Fri, 31 Dec 999 23:59:59 GMT";

I understand that I should use these codes, but I can't execute them well.
I also don't know how to delete all cookies.
I would appreciate it if someone could tell me.

javascript cookie

2022-11-24 22:15

1 Answers

I just searched by keyword, but I found the following example for deleting all cookies.

Perform the deletion of javascript cookies

If you want to delete all cookies, you can do the following:

const clearAllCookies=()=> 
    document.cookie.split(';').forEach(cookie=> document.cookie=cookie.replace(/^+/, ').replace(/=.*/,`=;max-age=${0};`));


2022-11-24 22:37

If you have any answers or tips

© 2022 OneMinuteCode. All rights reserved.