? Deleting All of My Site's Cookies / Using Wildcards With Cookie

A

Alec S.

Hi,

I'm using JavaScript and Cookies for some customization in a web page.
There may be several values in the cookie with names that are not known at
runtime. I need a way of deleting them.

For example, if my site is www.test.com and the cookie contains:

label1
fob
....
*

name1
foo
....
*
name2
bar
....
*
name3
baz
....
*

and so on, then I would write a function that simply deletes these values
with a loop that counts off name1, name2, name3, et cetera. Unfortunately
my cookie will use different labels, not name1, name2, name3..., in fact I
have no way of knowing exactly what they will be called beforehand although
they will have some things I can predict.

Can I use wildcards in the value-name, eg. in the above example, could I
delete "name*" or "*1"? Alternatively, is there a way to just delete ALL
values in the cookie?


Thanks.
 
A

Alec S.

Oh, and I know I have to set the value to expire to delete it. What I'm
looking for is a way to expire unknown values (names).
 
R

Randy Webb

Alec said:
Oh, and I know I have to set the value to expire to delete it. What I'm
looking for is a way to expire unknown values (names).

Set the expiration date on the cookie to a past date, the cookie will be
expired and it will be gone. Then, you reset the cookie with the data
you want.
 
E

Evertjan.

Randy Webb wrote on 17 apr 2005 in comp.lang.javascript:
Set the expiration date on the cookie to a past date, the cookie will be
expired and it will be gone. Then, you reset the cookie with the data
you want.

You will have to trust the client time not being set in the past.
 
A

Alec S.

Like I said, I already know how to delete a cookie-value whose name I know.
I need a way of deleting a cookie-value whose name I DON'T know.
 
E

Evertjan.

Alec S. wrote on 17 apr 2005 in comp.lang.javascript:
Like I said, I already know how to delete a cookie-value whose name I
know.

This is usenet, please quote, if you are anwering someone.
I need a way of deleting a cookie-value whose name I DON'T know.

You should know their names since you set them.

=================

With serverside ASP [sorry: vbs here] I can read them all:

Cookies Variables <br>
<% For each d in Request.Cookies %>
<%=d%>
=
<%=Request.Cookies(d)%>
<br>
<% Next %>

And then set their content on "" and the expiry on 1 jan 1970

Serverside javascript goes about the same,
but with clientside javascript I doubt, if it is possible.
 
A

Alec S.

This is usenet, please quote, if you are anwering someone.

I didn't quote because I was replying to someone who replied to someone who
replied to me. Should I cut and paste multiple quotes, especially if they
are long? Most, if not all newsreaders these days display messages in a
"thread" which makes it easy enough to find the reference.

You should know their names since you set them.

Think about it this way. I have two text boxes in a form. The user enters
some text in them. I take that text from the first box and set a cookie
using that user-entered text as the name/label passing the text from the
second box as the value.

This isn't exactly the way I'm doing it but it's close enough to explain why
I don't know the name of the cookie. I need either a way of deleting all
cookies made at my site, simply deleting the whole cookie file associated
with my site, or some way of using wildcards—say for example if the user
must enter a username like 1234Blah where the 1234 is always the same and
the Blah is different.
 
E

Evertjan.

Alec S. wrote on 18 apr 2005 in comp.lang.javascript:
I didn't quote because I was replying to someone who replied to
someone who replied to me. Should I cut and paste multiple quotes,
especially if they are long? Most, if not all newsreaders these days
display messages in a "thread" which makes it easy enough to find the
reference.

Please dont try to reinvent netiquette.
Think about it this way. I have two text boxes in a form. The user
enters some text in them. I take that text from the first box and set
a cookie using that user-entered text as the name/label passing the
text from the second box as the value.

This isn't exactly the way I'm doing it but it's close enough to
explain why I don't know the name of the cookie.

Cookie handling is versatile enough not to be used this way

Strange you give so much room to these two sentences of mine
and do not address the real answer I gave.

Prossibly because you did not quote, you forgot that answer? ;-}
 
A

Alec S.

Evertjan. said:
Randy Webb wrote on 17 apr 2005 in comp.lang.javascript:


You will have to trust the client time not being set in the past.
and


You should know their names since you set them.


There, I quoted, adding a lot more text to download which is annoying for
dial-up users. I am not reinventing netiquette, but using guidelines that
many people—other than yourself—follow.


Either way, you did not help by saying that I should know the names nor by
saying that I need to trust the user's system clock. If you are feeling
hostile, judgmental, and critical and have no interest in helping then you
need not answer, I am sure there will be someone else who will give an
answer politely—and non-accusatorially—one way or another. It's so annoying
that there are grouchy people like you trolling everywhere.
 
E

Evertjan.

Alec S. wrote on 19 apr 2005 in comp.lang.javascript:
Either way, you did not help by saying that I should know the names
nor by saying that I need to trust the user's system clock.

You will be the judge to if it helps you,
but both advises were made in an effort to help you.

The same goes for my final anwer to your OQ,
which you repeatedly forgot to address.
 
A

Alec S.

I addressed both of your answers:


1: > You should know their names since you set them.

I DON'T know the name. I gave a clear example why I would not know them.


2: > You will have to trust the client time not being set in the past.

I already know that to delete a cookie you have to expire it. That is NOT
what I asked.



I don't know how I can explain the question or why your answers were not
helpful any more clearly. Perhaps you should take your infinite knowledge
along with your demeanor elsewhere. There are plenty of places on the
Internet where irritable people can argue. People like you are anything BUT
helpful; if someone asks a question you freak out and call them stupid
because they don't know what you know which is exactly why they asked in the
first place. I just pray that you are not a teacher.
 
E

Evertjan.

Alec S. wrote on 19 apr 2005 in comp.lang.javascript:
I don't know how I can explain the question or why your answers were
not helpful any more clearly. Perhaps you should take your infinite
knowledge along with your demeanor elsewhere. There are plenty of
places on the Internet where irritable people can argue. People like
you are anything BUT helpful; if someone asks a question you freak out
and call them stupid because they don't know what you know which is
exactly why they asked in the first place. I just pray that you are
not a teacher.

Oh, oh, are we touchy.

Alec, this is usenet and not a paid helpdesk.

You cannot insist that responses to your questions must be helpfull to you
[or in fact you can, you can do what you like on usenet, but it would be an
unreasonable act]

So trying to explain why you find the responses not helpful, while I put to
you they were ment to be helpful, is not ferry useful, as I never insisted
you should find them so.

Saying that I must go away because you don't rate my answers high enough is
plainly silly, since if you have a problem, don't expect others to take the
consequences thereoff.

I did not call you stupid, perhaps you are projecting you own selfesteem?

I will now stop answering you.
 
H

Hallvord R. M. Steen

I'm using JavaScript and Cookies for some customization in a web page.
There may be several values in the cookie with names that are not known
at runtime. I need a way of deleting them.

Easy: document.cookie gives you all the cookie names.

var cookieArray = document.cookie.split( ';' );

for( var i=0; i<cookieArray.length; i++ ){

nameValueArray = cookieArray[ i ].split( '=' )
// now cookie name is nameValueArray[ 0 ],
//set it with expiry in the past
document.cookie = nameValueArray[ 0 ] + ';expires=Sun, 17 April 2005
05:06:09'
}


(Caveat: I didn't bother doublechecking if the date format is correct for
cookies.)
 
R

Richard Cornford

Hallvord said:
Easy: document.cookie gives you all the cookie names.

document.cookie - _may_ give you all the cookie names.

Internet "privacy" provided by content-inserting/re-writing proxies
often included a facility intended to prevent the client-side scripting
of cookies, that works by replacing the string "cookie" with an (any)
alternative wherever it appears in client-side script source code. The
expected outcome of this would be that - document.cookie - would return
undefined (having been transformed into - document.ignore - (for
example) by the proxy).
var cookieArray = document.cookie.split( ';' );
<snip>

The result of the actions of this type of proxy is that code that
assumes that - document.cookie - will return a string, and then goes on
to call a String object method, will error-out. Potentially taking out
related code that may not actually depend on successful cookie
interactions (or probably does not need to be designed to be dependent
on cookie use).

Applying a type-converting test to result of reading - document.cookie -
prior to applying any other operations to the resulting value avoids the
problem, and allows scripts to handle the unavailability of cookies
without erroring:-

var cky;
if((cky = document.cookie)){
... // document.cookie returned a value that type-converts
// to true, so not undefined or an empty string (which
// isn't worth reading anyway).
}

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top