SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Apr 2010
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    var expiredays = "1"; Change to 1 hour instead?

    In my JS code, I have this:

    Code:
    var expiredays = "1";
    which sets a "cookie" to expire in 1 day. However, I want it to expire in 1 hour instead. Is there a way to do that?

    Thanks

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Mr.Canuck View Post
    However, I want it to expire in 1 hour instead. Is there a way to do that?
    Yes, use Expires and set it to a date that's 1 hour ahead of now.

    If you use the createCookie function from these cookie handling functions then you can give it a day of 1/24 to have it expire in 1 hour.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Apr 2010
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply. Here is the snippet of code. How would I write this for 1 hour? Thanks:
    Code:
    function BookMark() {
     
    $('#BookmarkImg').animate({ "top": "-81px" }, 1000);
     
    baseCookieName = "rwbookmark";
     
    var exdate = new Date();
     
    var expiredays = "1";
     
    exdate.setDate(exdate.getDate() + expiredays);
     
    //use of arbritary stop point so no endless loop occurs
     
    for (var i = 0; i < 10000; i++) {
     
    var curName = baseCookieName + i;
     
    if (document.cookie.indexOf(curName) < 0) {
     
    document.cookie = curName + "=" + escape(window.location.href) + "[#]contentid=" + document.getElementById("inputContentID").value + "[#]title=" + GetPageTitle() + ";expires=" + exdate.toGMTString() + ";path=/;domain=domain.ca;";
     
    break;
     
    }

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Use setTime instead of setDate, as in the code that I linked you to before.

    For example:

    Code:
    date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •