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

Related Questions

I have the following script which displays data returned from a serverside page onto
Many applications have grids that display data from a database table one page at
I have a php page that displays rows from a mysql db as a
I want to make a page that displays some data from a DB, so
I have a web page that displays a long line graph inside a div
I have a simple cart page that displays items that are in someones cart,
I have a customer index page that displays customer lists. I have a search
I have an ASP.NET web page that displays a variety of fields that need
I have a ListView on a page that displays a list of widgets. When
I'd like to have a page in php that normally displays information based on

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.