View Full Version : Cookie deletes on page loads?

10-08-2007, 07:37 PM
Hey guys, I need help on this:

I have a cookie by the name "seenit" and i need it to be deleted/removed when it loads another document (i.e: bye.asp).
Your help will be greatly appreciated!

With Regards,

10-09-2007, 04:55 AM
If you are setting the cookie with javascript, you would need a site wide cookie. Use this code (about halfway down the page) to set it and to later delete it:


If it is a server side cookie (you mention a .asp page), refer to your asp documentation.

10-09-2007, 06:12 AM
Ouch... I still can't get it though... because I'm totally new to cookies, my apologies.

But here's the code for my first page:
// page to go to if cookie exists
go_to = "bye.asp";

// Cookies made to live for 30 minutes
num_days = 1;
function ged(noDays){
var today = new Date();
var expr = new Date(today.getTime() + noDays*30*60*1000);
return expr.toGMTString();

function readCookie(cookieName){
var start = document.cookie.indexOf(cookieName);
if (start == -1){
document.cookie = "seenit=yes; expires=" + ged(num_days);
} else {
window.location = go_to;

// -->

So how do I have it erased when it loads 'bye.asp'? I went through with the tutorial but they kept prompting me that there's an error and I couldn't solve it.

10-09-2007, 04:57 PM
Anyone, please?

10-09-2007, 05:05 PM
That doesn't look like the code that I suggested that you use.

10-09-2007, 06:28 PM
I'm sorry, pal... because I needed a cookie that will automatically redirect the user to another page if the cookie is present; having no choice, I took the script from somewhere else. But thank you so much for your help, I really appreciate it.

Also, I've found the solution to erase the cookie already, it's just this 1-line of code:
document.cookie="seenit=; expires=Mon, 9 Oct 2006 18:23:58 UTC";

Anyway, thanks alot! All the best and have a nice day ahead!

With regards,

10-09-2007, 07:20 PM
Now that you've explained the situation a bit better by providing the solution that you think you were looking for, I can add that I don't think that it will work in all browsers if more than one page is involved in reading/writing, and deleting the cookie.

The code I pointed you to provides three functions for reading, writing, and erasing javascript cookies that work across an entire domain for all browsers.

If your project requires that it function as expected for all users, has security issues involved, or needs to work when a user logs on using different computers, javascript cookies should not be employed. Asp provides for server side cookies that are secure and that will function even with javascript disabled.