Js to get browser information

Source: Internet
Author: User
Tags setcookie
Tip: you can modify some code before running

<scriptlanguage="JavaScript" type="text/javascript">Var newline = "rr"<!--变量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 ("Enter your name :",'');<!--弹出提示窗口-->SetCookie ('visitorname', VisitorName, exp );<!--将用户输入的昵称写入cookie中-->} Return VisitorName;<!--返回用户的昵称-->} Function When (info ){<!--返回用户的上次访问时间-->Var rightNow = new Date ()<!--构造变量-->Var WWHTime = 0; WWHTime = GetCookie ('whenh ')<!--从cookie中获取上一次的时间-->WWHTime = WWHTime * 1var 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 ('whcount', WWHCount, exp );<!--同时将更新过的信息写入cookie中-->Return WWHCount;<!--返回上站次数-->} Function set () {VisitorName = prompt ("Enter your new name :",'');<!--弹出窗口,提示输入昵称-->SetCookie ('visitorname', VisitorName, exp );<!--将用户昵称写入cookie中-->SetCookie ('whcount', 0, exp );<!--将用户上站次数0写入cookie中-->SetCookie ('whenh', 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 + browser + newline + clock + newline + loadTimeResult + newline + internetTime + newline + screenresolution + newline + lastdoc + newline + countvisits + newline + javaenabled + newline + response + newline + newline )}</script><body onLoad="showAlert()"><!--本例程实现了显示访客系统信息的功能--><!--访客的登陆信息包括访客的昵称、访问的次数以及上次访问的时间--><!--访客的系统信息包括浏览器格式及版本、当前时间、页面载入时间、显示器的分辨率等--><!--cookie的读写操作--><!--时间函数以及字符串函数的使用方法-->
Tip: you can modify some code before running

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.