Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 602885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:52:15+00:00 2026-05-13T16:52:15+00:00

I have a page that displays data which is read from a cookie. The

  • 0

I have a page that displays data which is read from a cookie. The cookie expires after an hour. Frequently, a user will navigate to the page and keep it open. When they come back to it later, the cookie has expired and the data on the page is no longer relevant.

Can anyone suggest how I can set the cookie’s expiration time to last the length of the session?

For reference, this is the code I’m using to set the cookie (which I lifted from another project we have, and which may in turn have been lifted from this site! 🙂

function setCookie(value)
{
    var today = new Date();
    today.setTime(today.getTime());
    var expires = 30 * 1000 * 60;

    var c_name = 'CompareFundIds';
    var exdate = new Date(today.getTime() + (expires));
    document.cookie = c_name + "=" + value + ";expires=" + exdate.toGMTString();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:52:16+00:00Added an answer on May 13, 2026 at 4:52 pm

    Your headline and text seem to state two different requirements:

    1. cookie must remain valid until browser is closed, then disappear
    2. cookie must remain valid until browser is closed, then remain valid for another hour, then disappear

    1) will work if you set no “expires” value at all for the cookie:

    // Set cookie until browser is closed
    document.cookie = c_name + "=" + value;
    

    2) will work if you let your setCookie function run repeatedly as long as the page is open, say every minute:

    // Set cookie every minute
    var value = ...;
    window.setInterval(function () {
        setCookie(value);
    }, 60 * 1000);
    

    When the browser is closed, the cookie will never be older than 1 minute and will thus be valid for another hour.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 303k
  • Answers 303k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to specify an empty query for your substitution… May 13, 2026 at 8:39 pm
  • Editorial Team
    Editorial Team added an answer The fix was to install a facelets jar. See here. May 13, 2026 at 8:39 pm
  • Editorial Team
    Editorial Team added an answer from django.db import models url(r'^create_(?P<modelname>\w+)/$', generic_add), def generic_add(request, modelname): mdlnm_model… May 13, 2026 at 8:39 pm

Related Questions

I'm new to MVC, but I've been all over this, read all the documentation
I've been playing around with ASP.NET MVC with a site containing a Master Page.
I built an online news portal before which is working fine for me but
I am using file_get_contents to grab a page, but i need to replace some
I'm working on the Web GUI of an appliance-like product. I have an HTML

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.