Js visitor access code

Source: Internet
Author: User

<Script language = "JavaScript">
<! -- Hide this script from old browsers --
Var expDays = 30;
Var exp = new Date ();
Exp. setTime (exp. getTime () + (expDays * 24*60*60*1000 ));
Function Who (info ){
Var VisitorName = GetCookie ('visitorname ')
If (VisitorName = null ){
VisitorName = prompt ("Enter name :",'');
SetCookie ('visitorname', VisitorName, exp );
}
Return VisitorName;
} Function When (info ){
Var rightNow = new Date ()
Var WWHTime = 0;
WWHTime = GetCookie ('whenh ')

WWHTime = WWHTime * 1
Var lastHereFormatting = new Date (WWHTime); // Date-I-fy that number
Var intLastVisit = (lastHereFormatting. getYear () * 10000) + (lastHereFormatting. getMonth () * 100) + lastHereFormatting. getDate ()
Var lastHereInDateFormat = "" + lastHereFormatting; // Gotta use substring functions
Var dayOfWeek = lastHereInDateFormat. substring (0, 3)
Var dateMonth = lastHereInDateFormat. substring (4, 11)
Var timeOfDay = lastHereInDateFormat. substring (11,16)
Var year = lastHereInDateFormat. substring (23, 25)
Var WWHText = dayOfWeek + "," + dateMonth + "at" + timeOfDay // display
SetCookie ("WWhenH", rightNow. getTime (), exp)
Return WWHText;
}
Function Count (info ){
Var WWHCount = GetCookie ('wwhcount ')
If (WWHCount = null ){
WWHCount = 0;
}
Else {
WWHCount ++;
}
SetCookie ('whcount', WWHCount, exp );
Return WWHCount;
}
Function set (){
VisitorName = prompt ("?????? ",'');
SetCookie ('visitorname', VisitorName, exp );
SetCookie ('whcount', 0, exp );
SetCookie ('whenh', 0, exp );
}
Function getCookieVal (offset ){
Var endstr = document. cookie. indexOf (";", offset );
If (endstr =-1)
Endstr = document. cookie. length;
Return unescape (document. cookie. substring (offset, endstr ));
}
Function GetCookie (name ){
Var arg = name + "= ";
Var alen = arg. length;
Var clen = document. cookie. length;
Var I = 0;
While (I <clen ){
Var j = I + alen;
If (document. cookie. substring (I, j) = arg)
Return getCookieVal (j );
I = document. cookie. indexOf ("", I) + 1;
If (I = 0) break;
}
Return null;
}
Function SetCookie (name, value ){
Var argv = SetCookie. arguments;
Var argc = SetCookie. arguments. length;
Var expires = (argc> 2 )? Argv [2]: null;
Var path = (argc> 3 )? Argv [3]: null;
Var domain = (argc> 4 )? Argv [4]: null;
Var secure = (argc> 5 )? Argv [5]: false;
Document. cookie = name + "=" + escape (value) +
(Expires = null )? "": ("; Expires =" + expires. toGMTString () +
(Path = null )? "": ("; Path =" + path) +
(Domain = null )? "": ("; Domain =" + domain) +
(Secure = true )? "; Secure ":"");
}
Function DeleteCookie (name ){
Var exp = new Date ();
Exp. setTime (exp. getTime ()-1 );
// This cookie is history
Var cval = GetCookie (name );
Document. cookie = name + "=" + cval + "; expires =" + exp. toGMTString ();
}
// -- End Hiding Here -->
</Script>
Add the following original code between <body> </body>:
<Script language = "JavaScript">
<! -- Hide this script from old browsers --
Document. write ("Hello <B>" + Who () + "</B>, you are the <B>" + Count () + "</B> visits to the home page. the last time is <B> "+ When () +" </B>. ")
Document. write ('<a href = "JavaScript: set ()"> [Change the name here] </a> ')
// -- End Hiding Here -->
</Script>

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.