/    Sign up×
Community /Pin to ProfileBookmark

How do I delete All cookies

Hi, I know this must be a simple thing, but I can’t figure it out.
I have several cookies on my webpage, I did a list with
write.document (cookie), then I attempted to delete all cookies
with some JS code I picked up on the net. I won’t waste time trying
to correct the code or my mistake, all I am asking is for some easy way
to delete all, when I am not sure of the Cookie name or Path..
Send code or point me to somplace where I might find an answer
that even a caveman could understand..

Thanks….

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@mrhooMay 11.2008 — I won't waste time trying

to correct the code or my mistake[/quote]

That's the spirit.

Although you can parse a cookie to return its name you can't read the path.

If you don't know the cookie name and path you cannot remove it.

Otherwise, save the same cookie name and path with an expires value that has already passed.
Copy linkTweet thisAlerts:
@mlimMay 11.2008 — Try using the Standard tool bar above,

Tools, Internet Options, Delete Cookies
Copy linkTweet thisAlerts:
@tooldforthisauthorMay 11.2008 — Sometimes we need to re-read our notes for clarity.

I did say

I won't waste time trying

to correct the code or my mistake,,

What I meant is I did not want to waste the readers time by posting

a page of coding, that does not work.

Also I should have made it clear that I was not attempting to delete

all the user cookies on my computer, I was only interested in deleting

cookies I created during some testing of the different cookie scenarios

such as document.cookie or set cookie...

I will probably end up changing the expire dates as soon as I can figure out

how to ....

get rid of these..

Order.2; Order.3; Order.4; Order.5; Order.6;

I tried creating a new cookie with expiration date -1

for these cookies but it just is not working..

Sorry for the poor wording of my original note..

Thanks for any and all help..

Frank
Copy linkTweet thisAlerts:
@mrhooMay 11.2008 — This may work, but you need to use it on a page in every directory that sets cookies for its own folder path.

You have to do it client side, because that's where the cookies are...

It gets all the cookie names from the curent page,

and then writes an expired cookie for the current folder path,

and additional expired cookies all the way up to the root folder.

[CODE]function destroyAllCookies(){
var C= document.cookie;
if(!C) return;
var M,cook,str,ex,path;

ex= new Date();
ex.setDate(ex.getDate()-1);
ex= ex.toUTCString();// yesterday's date in GMT

var Rx= /([a-z]+) *= *([^;]+;)?/ig
while((M= Rx.exec(C))!= null){
cook= M[1]; // the name part of each cookie
str=cook+'=;expires='+ex;
document.cookie= str; // no path (current folder)
str+= ';path=';
document.cookie= str+'/'; // root path
var path= location.pathname;
while(path){
path= path.substring(0,path.lastIndexOf('/'));
if(path)document.cookie= str+path;
}
}
}[/CODE]
×

Success!

Help @tooldforthis spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...