I need to delete clientside cookies with the same name but with different paths. What is the best way to do this in javascript.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Just specify the same path of the cookie you want to remove, giving it a past expiration.
Changing it to expire the cookie with a path of
/will still only expire one of the cookies — the path given has to match the path set:To remove both, you’ll have to expire each with their path:
Now, these examples assume you’re browsing
/path/or a sub-directory of it.[edit]
To remove in bulk, try something like this:
Demo: http://jsfiddle.net/M2dZ3/
You can also fake path lookups by splitting and iterating
window.location.pathname:Demo: http://jsfiddle.net/M2dZ3/2/