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

📄 9-12.htm

📁 学习网页制作的好工具
💻 HTM
字号:



<script
language="JavaScript" type="text/javascript">

	var newline = "\r\r"                <!--变量newline代表两个回车符-->
	var now = new Date()                <!--变量now代表客户机系统的时间-
	var millinow=now.getTime()/1000     <!--变量millinow表示以毫秒表示的日期和时间的千分之一-->
	var hours = now.getHours()          <!--变量hours表示小时值-->
	var minutes = now.getMinutes()      <!--变量minutes表示分钟值-->
	var seconds = now.getSeconds()      <!--变量seconds表示秒值-->
	var yourLocation=""                 <!--定义表示居住位置的字符串-->
	
	now.setHours(now.getHours()+1)      
	var min=60*now.getUTCHours()+now.getUTCMinutes() + now.getUTCSeconds()/60;
	var internetTime=(min/1.44)
	internetTime="Internet Time: @"+Math.floor(internetTime)  <!--将小于上述值的最大整数值作为internetTime-->

	var clock = "It's exactly "+hours+":"+minutes+":"+seconds+" hours"	<!--将当前时间的小时分秒按一定的格式赋给变量clock-->
	var browser = "You are using " + navigator.appName +" "+navigator.appVersion   <!--将所用的浏览器的名称和版本号按一定的格式赋给变量browser-->
	yourLocation="You are probably living in "+yourLocation    <!--将所在位置字符串按一定格式赋给变量yourlocation-->
	
	var winwidth= window.screen.width              <!--用户显示屏的宽度-->
	var winheight= window.screen.height            <!--用户显示屏的高度-->
	var screenresolution= "Screen resolution: "+window.screen.width+" x "+window.screen.height    <!--分辨率变量-->
	var lastdoc = "You came from: "+document.referrer<!--用户的位置-->
	
	
	var expDays = 30;<!--cookie的期限-->
var exp = new Date(); <!--新的时间变量-->
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));<!--过期的日期-->

function Who(info){<!--获得访问者的昵称-->
var VisitorName = GetCookie('VisitorName')<!--先从cookie中查找visitorName字段
if (VisitorName == null) {<!--如果没有找到,则提示用户输入昵称-->
VisitorName = prompt("请输入你的称呢:",'');<!--弹出提示窗口-->
SetCookie ('VisitorName', VisitorName, exp);<!--将用户输入的昵称写入cookie中-->
}
return VisitorName;<!--返回用户的昵称-->
}
function When(info){<!--返回用户的上次访问时间-->
var rightNow = new Date()<!--构造变量-->
var WWHTime = 0;
WWHTime = GetCookie('WWhenH')<!--从cookie中获取上一次的时间-->

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)<!--将用户访问时间和过期时间均写入cookie中-->
return WWHText;
}

function Count(info){<!--返回用户上站次数-->
var WWHCount = GetCookie('WWHCount')<!--从cookie中读取wwwhcount字段-->
if (WWHCount == null) {<!--如果返回值为空-->
WWHCount = 0;<!--上站次数为0-->
}
else{
WWHCount++;<!--否则,上站次数加1-->
}
SetCookie ('WWHCount', WWHCount, exp);<!--同时将更新过的信息写入cookie中-->
return WWHCount;<!--返回上站次数-->
}


function set(){
VisitorName = prompt("请输入你的新称呢:",'');<!--弹出窗口,提示输入昵称-->
SetCookie ('VisitorName', VisitorName, exp);<!--将用户昵称写入cookie中-->
SetCookie ('WWHCount', 0, exp);<!--将用户上站次数0写入cookie中-->
SetCookie ('WWhenH', 0, exp);<!--将用户最后上站时间写入cookie中-->
}

function getCookieVal (offset) {<!--返回cookie中一定位置的字段-->
   var endstr = document.cookie.indexOf (";", offset);<!--获取指定位置字段的末尾的位置-->
   if (endstr == -1)<!--如果返回值为-1-->
     endstr = document.cookie.length;<!--则将给定位置后的所有字符串均返回-->
  return unescape(document.cookie.substring(offset, endstr));<!--返回字符串-->
}

function GetCookie (name) {<!--从cookie中获取字段的值-->
        var arg = name + "=";<!--变量-->
      var alen = arg.length;<!--字段的长度-->
        var clen = document.cookie.length;<!--cookie的长度-->
        var i = 0;
        while (i < clen) {<!--在cookie中-->
               var j = i + alen;<!--移动一个字段的宽度-->
                if (document.cookie.substring(i, j) == arg)<!--如果是待找字段-->
                        return getCookieVal (j);<!--返回字段的值-->
                i = document.cookie.indexOf(" ", i) + 1;<!--更新i的值-->
                        if (i == 0)
                                break;<!--如果找完了,返回-->
               }
   return null;
}

function SetCookie (name, value) {<!--向cookie中写入-->
        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" : "");<!--按照给定的格式写入cookie-->

}


var countvisits="You've been here " + Count() + " time(s). Last time was " + When() +"."<!--将登陆的次数和时间构成一个字符串-->



if (navigator.javaEnabled()) {<!--判断浏览器中的java applet是否被启用-->
   var javaenabled="Your browser is able to run java-applets";<!--被启用-->
}

else {
   var javaenabled="Your browser is not able to run java-applets";<!--未被启用-->
}


function showAlert() {<!--显示提示窗口-->
	var later = new Date()
	var millilater=later.getTime()/1000 <!--记录后来的时间-->
	var loadTime=(Math.floor((millilater-millinow)*100))/100<!--计算页面载入时间-->
	var loadTimeResult= "It took you "+loadTime+" seconds to load this page"<!--显示页面载入时间-->
	var babiesborn=Math.ceil(loadTime*4.18)<!--计算在这段时间内出生的婴儿数目-->
	var babiesbornresult="While this page was loading "+babiesborn+" babies have been born"<!--显示出生的婴儿数目-->
	if (babiesborn==1){babiesbornresult="While this page was loading "+babiesborn+" baby has been born"}<!--区分单、复数-->
	<!--弹出提示窗口-->
	alert(newline+newline+browser+newline+clock+newline+loadTimeResult+newline+internetTime+newline+screenresolution+newline+lastdoc+newline+countvisits+newline+javaenabled+newline+babiesbornresult+newline+newline)
}

</script>


<body onLoad="showAlert()">



<!--本例程实现了显示访客系统信息的功能-->
<!--访客的登陆信息包括访客的昵称、访问的次数以及上次访问的时间-->
<!--访客的系统信息包括浏览器格式及版本、当前时间、页面载入时间、显示器的分辨率等-->
<!--cookie的读写操作-->
<!--时间函数以及字符串函数的使用方法-->

⌨️ 快捷键说明

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