⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 11-3.htm

📁 JScript网页特效,包含很多的实现网页特效的方法.
💻 HTM
字号:
<html>
<head>
<title>§11.3 统计用户来访次数</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript">
<!-- Begin
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("您的尊姓大名:");
    SetCookie ('VisitorName', VisitorName, exp);
  }
  return VisitorName;
}

function When(info)       //存取用户上次访问时间
{
  var rightNow = new Date()
  var WWHTime = 0;
  WWHTime = GetCookie('WWhenH')
  WWHTime = WWHTime * 1
  var lastHereFormatting = new Date(WWHTime);
  var intLastVisit = (lastHereFormatting.getYear() * 10000)+(lastHereFormatting.getMonth() * 100) + lastHereFormatting.getDate()
  var lastHereInDateFormat = "" + lastHereFormatting;
  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
  SetCookie ("WWhenH", rightNow.getTime(), exp)
  return WWHText
}

function Count(info)       //统计用户访问次数
{  
  var WWHCount = GetCookie('WWHCount')
  if (WWHCount == null) 
  {
    WWHCount = 0;
  }
  else
  {
    WWHCount++;
  }
  SetCookie ('WWHCount', WWHCount, exp);
  return WWHCount;
}

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)      //读取指定名称的cookie值函数
{// alert(document.cookie)
  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);
    if (i == -1) break;
    i+=2;
  }
  return null;
}

function SetCookie (name,value,x_expires,x_path,x_domain,x_secure)  //设置一个Cookie值函数
{
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? x_expires : null;
  var path = (argc > 3) ? x_path : null;
  var domain = (argc > 4) ? x_domain : null;
  var secure = (argc > 5) ? x_secure : 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)    //删除Cookie值函数
{
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);
  var cval = GetCookie (name);
  document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

//  End -->
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000">
 <script language="JavaScript">

function delcookie()      //删除cookie
{
  DeleteCookie("VisitorName");
  DeleteCookie("WWHenH");
  DeleteCookie("WWHCount");
  alert("删除成功!");
}
 
 cou=Count()
if (cou==0)
{
  document.write("您好!" + Who() + ". 您首次来这儿,请多提宝贵意见.");
}
else
{
  temp="您好!" +Who() 
  temp += "您已来这儿" + cou + "次了,最后一次在 " + When() +"."
  document.write(temp);
  
  temp="<a href=\"#\" onclick=\"delcookie()\">删除COOKIE值</a>"
  document.write(temp);
}
</script>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -