How do you delete all the cookies for the current domain using JavaScript?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
After a bit of frustration with this myself I knocked together this function which will attempt to delete a named cookie from all paths. Just call this for each of your cookies and you should be closer to deleting every cookie then you were before.
As always different browsers have different behaviour but this worked for me. Enjoy.
Figured I'd share this method for clearing cookies. Perhaps it may be helpful for someone else at some point.
Here's a simple code to delete all cookies in JavaScript.
Run the function
deleteAllCookies()
to clear all cookies.Simpler. Faster.
An answer influenced by both second answer here and W3Schools
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