title: Get A Cookie to Not Expire While Page is Open, But Last 1 Hour When It's Closed
body: <p>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.</p>
  
  <p>Can anyone suggest how I can set the cookie's expiration time to last the length of the session?</p>
  
  <p>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! :-)</p>
  
  <pre><code>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();
  }
  </code></pre>