/    Sign up×
Community /Pin to ProfileBookmark

How to check and confirm whether my cookies in web browser is deleted or not.

Hi All

I am doing task for deleting cookies in javascript for IE and Mozilla.
for that i written function is

[QUOTE]

function deleteCookie(name, path, domain) {
if (getCookies(name)) {
document.cookie = name + “=” +
((path) ? “; path=” + path : “”) +
((domain) ? “; domain=” + domain : “”) +
“; expires=Thu, 01-Jan-70 00:00:01 GMT”;
}
[B] alert(‘document.cookie value :::::’+document.cookie);[/B]
}
function getCookies(name) {
var dc = document.cookie;
var prefix = name + “=”;
var begin = dc.indexOf(“; ” + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);

} else

begin += 2;
var end = document.cookie.indexOf(“;”, begin);
if (end == -1)
end = dc.length;

return unescape(dc.substring(begin + prefix.length, end));
}

[/QUOTE]

in above code, i am getting proper alert with some value. alert is placed at the end of deleteCookie () method.

Now , How i know whether my cookies get deleted or not.I am not sure whether my browser cookies are deleted or not

Is there any test is there from where i can confirm the same.

Any input is highly appreciated.

Regards
Haresh

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@cluefulJan 17.2011 — To confirm that a cookie is deleted, you just attempt to read it. The result should be null or "".

Remember that if a cookie was set with a path parameter, the same parameter must be applied to delete it.
Copy linkTweet thisAlerts:
@guravharshaauthorJan 18.2011 — Hi all

In alert message that written at the end of deletecookie method gives me some message with unknown character.

that means my cookies are deleted or not?

or i need to modify my javascript deletecookie function?

Thanks

Haresh
Copy linkTweet thisAlerts:
@cluefulJan 18.2011 — Hi all

In alert message that written at the end of deletecookie method gives me some message with unknown character.

that means my cookies are deleted or not?

or i need to modify my javascript deletecookie function?
[/QUOTE]
I don't know what you mean by 'unknown character'. If you alert( document.cookie ), it shows all the cookies visible on the current domain:

[FONT="Courier New"]name1=value1;name2=value2 etc.[/FONT]

If a cookie fails to delete, it is because it was set with a higher level path than the current location. You can delete such a cookie by overwriting it with an expired date, [I]using the same path that was used to set it[/I].

The usual way to delete a cookie is to call your [I]setCookie[/I] function using a negative duration.
×

Success!

Help @guravharsha 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.29,
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,
)...