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 6605825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:19:47+00:00 2026-05-25T19:19:47+00:00

Following is a script+HTML that tells the user his last visit to page. <html

  • 0

Following is a script+HTML that tells the user his last visit to page.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cookie</title>
<script type="text/javascript">
window.onload = initLastVisit;

function initLastVisit() {
var now = new Date();
var last = new Date();
now.setMonth(now.getMonth()+6);
document.cookie = "lastVisit=" + last.toDateString() + ";path=/;expires=" + now.toGMTString();
document.getElementById("lastVisitedOn").innerHTML = document.cookie.split("=")[1];
}
</script>
</head>

<body>
<form>
<label>Enter your name&nbsp;&nbsp;<input type="text" id="name_field" /></label> <br/>
</form>
<h1 id="lastVisitedOn"></h1>
</body>
</html>

The statement that sets the cookie in the above script is : document.cookie = "lastVisit=" + last.toDateString() + ";path=/;expires=" + now.toGMTString(); . If in this i replace now.toGMTString() with now.toDateString() the expire time in the browser is “Expires when i close my browser” . Why is that ?
It is ok with toGMTString . The expire date is in march 2012 as expected.

  • 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-25T19:19:48+00:00Added an answer on May 25, 2026 at 7:19 pm

    If you try them both in the console, you will see that they don’t give the same resulting string at all:

    (new Date()).toGMTString();
    "Fri, 23 Sep 2011 16:33:01 GMT"
    
    (new Date()).toDateString();
    "Fri Sep 23 2011"
    

    When you set a cookie you have to specify the time using GMT format, if you don’t your browser fail to recognize the expiry time and consider that none was specified. When no expiry date is specified, cookie are created as “session cookie”, which expires once the session end (eg you close your browser).

    So when you use toDateString(), it is an invalid expiry format, your browser discards it and use its default value of creating a session cookie.

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

Sidebar

Related Questions

I have the following code on an html page: <script type=text/javascript> <!-- window.location.replace(http://www.example.com/); -->
Sometime during the dark ages a script was built that outputs the following html..
I have the following code that works fine in IE: <HTML> <BODY> <script language=JavaScript>
I am trying to use the following script by duckrowing ( http://www.duckrowing.com/2010/03/18/documenting-objective-c-with-doxygen-part-ii/ ), to
The Images section of the following document https://developers.google.com/apps-script/html_service says that only images hosted on
I use the following script for get the values from HTML Table.If I use
I'm using the following script to request new content to a file called index.html:
I am runing the following jquery script: <html> <head> <script type=text/javascript src=jquery.js></script> <script type=text/javascript>
I have the following directory structure : /script/x.js /includes/x.txt /1/2/index.html After hooking a webpage
I have the following KnockoutJS template (render with jquery.tmpl): <script id=contactsTemplate type=text/html> <li data-bind=click:

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.