Beginners JavaScript Cookie (2)

Source: Internet
Author: User
Tags date format getdate
cookie| Beginners

After experimenting and studying the sample program above, you will find that:

1. You are not able to read and display cookies. If you want to look at this cookie you need to specify another string variable that is the same as it:
Document.cookie = cookiename + "=" + Cookievalue + "; expires= "+ cookieexpires;
MyVar = cookiename + "=" + Cookievalue + "; expires= "+ cookieexpires;
document.write (MyVar);

2. The browser uses a different date format:
Netscape uses "GMT" to end, IE uses "UTC" because it can better build a date, as follows:
var expdate = new Date ()
Cookieexpires.settime (Expdate.gettime () + 1 * (* * * 1000))//+1 Day
Cookieexpires.togmtstring ()

When you show the date part
document.write (Expdate.getyear () + "<br>" + expdate.getmonth () + "<br>" + expdate.getdate ());
For the 2000-11-15 date, shown in IE as 2000/10/15, under Netscape display 100/10/15 (note: Some of the lower versions of the
Netscape browser's Y2K problem)

In the example, you see a section like the following:
if (Platform = = "Mac") {
Lastvisit = lastvisit-(24 * 60 * 60 * 1000)
}
But I can't detect it.

Date objects have getdate and Getday methods, and the second method returns the index number of the week's transit.

----------------------------------------
Knowing this, basically there is no problem (now you can take a look at homepage.htm)

[Translator: Copy the last sample code in this article to a text file and save the HTM format, and then run]

The last thing to say is that this is not only a dedicated JS script, if you want to use it on your Web page you have to minimize the use of different browsers to test it and notice their version, many of the scripting program contains browser type detection and a large number of if...else statements to handle this difference.

Sample page homepage.htm source code

=======================================



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.