Results 1 to 7 of 7

Thread: Cookie deletes on page loads?

  1. #1
    Join Date
    Oct 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Cookie deletes on page loads?

    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,
    Seng

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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:

    http://www.quirksmode.org/js/cookies.html

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

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Oct 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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:
    ------------------------------------
    <script>
    // 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;
    }
    }

    readCookie("seenit");
    // -->
    </script>
    ------------------------------------

    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.

  4. #4
    Join Date
    Oct 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Anyone, please?

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    That doesn't look like the code that I suggested that you use.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Oct 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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,
    Seng

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •