JavaScript implementation of the counter function code

Source: Internet
Author: User
Tags return setcookie domain
Javascript| counter

<script language= "JavaScript" >
<!--
function www_webjx_com (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 www_webjx_com (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= (2<ARGC) argv[2]:null;
var path= (3<ARGC) argv[3]:null;
var domain= (4<ARGC) argv[4]:null;
var secure= (5<ARGC) Argv[5]:false;
document.cookie=name+ "=" +escape (value) + (expires==null)? ":("; Expires= "+expires.togmtstring ()) + (Path==null)" ":("; Path= "+path") + (domain==null)? ":("; domain= "+domain)" + ((secure==true)? "; Secure ":" ");
}

var expdate=new Date ();
var visits;

Expdate.settime (Expdate.gettime () + (24*60*60*1000*365)); Set the cookie time for 1 years, you set the time casually

if (!) ( Visits=getcookie ("visits"))
visits=0;visits++; Setcookie ("Visits", visits,expdate, "/", null,false);
The following information shows that you can use the standard HTML syntax and set yourself casually
document.write ("You have to visit this page" + "<font color=red>" +visits+ "</FONT>" + "Times! ");
if (visits==1)//visit 1 times of information display
document.write ("<br>" + "Welcome to the site, feel the content of this site?" ");
if (visits==2)//Visit 2 times The information shows, the following analogy, oneself casually increase
document.write ("<br>" +) Come again Jong! Welcome to click on this site ads. ");
if (visits==3)
document.write ("<br>" + "regulars, in the forum of this site to send a post how?" ");
if (visits==4)
document.write ("<br>" + "you lunatic!");
if (visits>=5)
document.write ("<br>" + "crazy guy!") I really like you very much. ");
-->
</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.