View some user information with JavaScript

Source: Internet
Author: User
Tags date count return setcookie domain
JavaScript 1, detecting browser version

<script language= "JavaScript" >
<!--
document.write (navigator.appversion)
-->
</script>
2. Remember the number of visits

<script language= "JavaScript" >
<!--
var caution = False
function Setcookie (name, value, expires, path, domain, secure) {
var Curcookie = name + "=" + Escape (value) +
((expires)? "; Expires= "+ expires.togmtstring ():" ") +
((path)? "; Path= "+ Path:" "") +
(domain)? "; domain= "+ Domain:" "") +
(secure)? "; Secure ":" ")
if (!caution | | (name + "=" + Escape (value)). Length <= 4000)
Document.cookie = Curcookie
Else
if (Confirm ("Cookie exceeds 4KB and would be cut!"))
Document.cookie = Curcookie
}

function GetCookie (name) {
var prefix = name + "="
var cookiestartindex = document.cookie.indexOf (prefix)
if (Cookiestartindex = = 1)
return null
var cookieendindex = document.cookie.indexOf (";", Cookiestartindex + prefix.length)
if (Cookieendindex = = 1)
Cookieendindex = Document.cookie.length
Return unescape (document.cookie.substring (Cookiestartindex + prefix.length, Cookieendindex))
}

function Deletecookie (name, path, domain) {
if (GetCookie (name)) {
Document.cookie = name + "=" +
((path)? "; Path= "+ Path:" "") +
(domain)? "; domain= "+ Domain:" "") +
"; Expires=thu, 01-jan-70 00:00:01 GMT "
}
}

function Fixdate (date) {
var base = new Date (0)
var skew = Base.gettime ()
if (Skew > 0)
Date.settime (Date.gettime ()-skew)
}

var now = new Date ()
Fixdate (now)
Now.settime (Now.gettime () + 365 * 24 * 60 * 60 * 1000)
var visits = GetCookie ("Counter")
if (!visits)
Visits = 1
Else
visits = parseint (visits) + 1
Setcookie ("Counter", visits, now)
document.write ("You have come here" + visits + "times.")
-->
</SCRIPT>
3. Which Web page are you visiting from?

<script language= "JavaScript" >
document.write (Document.referrer)
</SCRIPT>
4. Date of last update

<script language= "JavaScript" >
<!--hide script from old browsers
document.write ("This page has been updated:" + document.lastmodified + "")
End Hiding-->
</script>
5, enter the name to welcome words

Place the following code between <script>
var name=prompt ("YOUR prompt message", "any inital VALUE")
</script>
</font>

Put the following code in the HTML file:
<center>
<font color=green>
<script>document.write (name);</script>
</font>
Other information to output ...</center>
</font>
6. Remember visiting time

<HTML>
<HEAD>
<title>name-visits-last visit</title>

<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 ("Your name:");
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 () *) + 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 set () {
Visitorname = Prompt ("Who are You?");
Setcookie (' Visitorname ', Visitorname, exp);
Setcookie (' Wwhcount ', 0, exp);
Setcookie (' Wwhenh ', 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);
var cval = GetCookie (name);
Document.cookie = name + "=" + Cval + "; Expires= "+ exp.togmtstring ();
}
End-->
</SCRIPT>

</HEAD>

<body bgcolor= #ffffff vlink= #0000ff >

<!--demonstration-->
<CENTER>
<script language= "JavaScript" >
if (Count () ==0)
{
document.write ("Hello!" + who () +. The first time you come here, please give me more valuable advice. ");
}
Else
{
document.write ("Hello!" + who () +. You have come here "+ Count () +" times, the last time in "+ when () +". ");
}
</SCRIPT>
</CENTER>
</BODY>
</HTML>

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.