Httml code:
Copy to ClipboardReference: [www.bkjia.com] <! Doctype html public "-// W3C // dtd html 4.01 // EN" "http://www.w3.org/TR/html4/strict.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Title> Untitled Document </title>
</Head>
<Body onload = "start ()">
</Body>
</Html>
JS Code:
Copy to ClipboardReference: [www.bkjia.com] <script language = "JavaScript" type = "text/javascript">
<! --
Function getCookie (name ){
If (document. cookie. length> 0 ){
Start = document. cookie. indexOf (name + "= ");
If (start! =-1 ){
Start = start + name. length + 1;
End = document. cookie. indexOf (";", start );
If (end =-1 ){
End = document. cookie. length;
}
Return decodeURI (document. cookie. substring (start, end ));
}
}
Return "";
}
Function setCookie (name, value, expires, path, domain, secure ){
Var curcookie = name + "=" + encodeURI (value)
+ (Expires )? "; Expires =" + expires. toGMTString ():"")
+ (Path )? "; Path =" + path :"")
+ (Domain )? "; Domain =" + domain :"")
+ (Secure )? "; Secure ":"");
Document. cookie = curcookie;
}
Function start (){
Var text = "";
Var visitorName = getCookie ("VisitorName ");
Var lasttime = getCookie ("time ");
Var isnMonth = new Array ", "August September", "August October", "August November", "August December ");
Var isnDay = new Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday ");
Var today = new Date ();
Var year = today. getYear ();
Var day = today. getDate ();
Var cookietime = year + "year" + isnMonth [today. getMonth ()] + day + "day" + isnDay [today. getDay ()];
Today. setTime (today. getTime () + 365*24*60*60*1000 );
SetCookie ("time", cookietime, today );
If (visitorName = ""){
VisitorName = prompt ("Input your name :");
SetCookie ("VisitorName", visitorName, today );
Document. write ("Hello," + visitorName + "Visit the customer's house for the first time. Please provide more valuable comments ");
}
Else {
Text + = "Hello," + visitorName + "+ "+ count () + ", <br> the last access time is:" + lasttime;
Document. write (text );
}
}
Function count (){
Var now = new Date ();
Now. setTime (now. getTime () + 365*24*60*60*1000 );
Var visits = getCookie ("counter ");
If (! Visits ){
Visits = 1;
} Else {
Visits = parseInt (visits) + 1;
}
SetCookie ("counter", visits, now );
Return visits;
}
-->
</Script>
Source: http://www.cnblogs.com/zghlx/