熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Javascript >> 正文

用JavaScript查看一些用戶信息

2022-06-13   來源: Javascript 
檢測浏覽器版本

<Script Language=JavaScript>
<!
documentwrite(navigatorappVersion)
//>
</script>
記住來訪次數

<SCRIPT LANGUAGE=JavaScript>
<!
var caution = false
function setCookie(name value expires path domain secure) {
    var curCookie = name + = + escape(value) +
        ((expires) ? ; expires= + expirestoGMTString() : ) +
        ((path) ? ; path= + path : ) +
        ((domain) ? ; domain= + domain : ) +
        ((secure) ? ; secure : )
    if (!caution || (name + = + escape(value))length <= )
        okie = curCookie
    else
        if (confirm(Cookie exceeds KB and will be cut!))
            okie = curCookie
}

function getCookie(name) {
    var prefix = name + =
    var cookieStartIndex = okieindexOf(prefix)
    if (cookieStartIndex == )
        return null
    var cookieEndIndex = okieindexOf(; cookieStartIndex + prefixlength)
    if (cookieEndIndex == )
        cookieEndIndex = okielength
    return unescape(okiesubstring(cookieStartIndex + prefixlength cookieEndIndex))
}

function deleteCookie(name path domain) {
    if (getCookie(name)) {
        okie = name + = +
        ((path) ? ; path= + path : ) +
        ((domain) ? ; domain= + domain : ) +
        ; expires=Thu Jan :: GMT
    }
}

function fixDate(date) {
    var base = new Date()
    var skew = basegetTime()
    if (skew > )
        datesetTime(dategetTime() skew)
}

var now = new Date()
fixDate(now)
nowsetTime(nowgetTime() + * * * * )
var visits = getCookie(counter)
if (!visits)
    visits =
else
    visits = parseInt(visits) +
setCookie(counter visits now)
documentwrite(您已來這兒 + visits + )
// >
</SCRIPT>
你從哪個網頁訪問過來

<Script Language=JavaScript>
documentwrite(documentreferrer)
</SCRIPT>
最後更新日期

<script language=JavaScript>
<!hide script from old browsers
documentwrite(This page has been updated: + documentlastModified + )
// end hiding >
</script>
輸入姓名至歡迎詞

把以下代碼放在<head></head>之間
<script>
var name=prompt(YOUR PROMPT MESSAGEANY INITAL VALUE)
</script>
</font>

把以下代碼放在HTML文件中
<center>
<font color=green>
<script>documentwrite(name);</script>
</font>
其它要輸出信息</center>
</font>
記住來訪時間

<HTML>
<HEAD>
<TITLE>Name Visits Last Visit</TITLE>

<SCRIPT LANGUAGE=JavaScript>
<! Begin
var expDays = ;
var exp = new Date();
expsetTime(expgetTime() + (expDays****));
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 = ;
WWHTime = GetCookie(WWhenH)
WWHTime = WWHTime *
var lastHereFormatting = new Date(WWHTime);
var intLastVisit = (lastHereFormattinggetYear() * )+
  (lastHereFormattinggetMonth() * ) + lastHereFormattinggetDate()
var lastHereInDateFormat = + lastHereFormatting;
var dayOfWeek = lastHereInDateFormatsubstring()
var dateMonth = lastHereInDateFormatsubstring()
var timeOfDay = lastHereInDateFormatsubstring()
var year = lastHereInDateFormatsubstring()
var WWHText = dayOfWeek + + dateMonth + at + timeOfDay
SetCookie (WWhenH rightNowgetTime() exp)
return WWHText
}
function Count(info){
var WWHCount = GetCookie(WWHCount)
if (WWHCount == null) {
WWHCount = ;
}
else{
WWHCount++;
}
SetCookie (WWHCount WWHCount exp);
return WWHCount;
}
function set(){
VisitorName = prompt(Who are you?);
SetCookie (VisitorName VisitorName exp);
SetCookie (WWHCount exp);
SetCookie (WWhenH exp);
}
function getCookieVal (offset) { 
var endstr = okieindexOf (; offset); 
if (endstr == )  
endstr = okielength; 
return unescape(okiesubstring(offset endstr));
}
function GetCookie (name) { 
var arg = name + =; 
var alen = arglength; 
var clen = okielength; 
var i = ; 
while (i < clen) {  
var j = i + alen;  
if (okiesubstring(i j) == arg)   
return getCookieVal (j);  
i = okieindexOf( i) + ;  
if (i == ) break; 
} 
return null;
}
function SetCookie (name value) { 
var argv = SetCookiearguments; 
var argc = SetCookieargumentslength; 
var expires = (argc > ) ? argv[] : null; 
var path = (argc > ) ? argv[] : null; 
var domain = (argc > ) ? argv[] : null; 
var secure = (argc > ) ? argv[] : false; 
okie = name + = + escape (value) +
((expires == null) ? : (; expires= + expirestoGMTString())) +
((path == null) ? : (; path= + path)) + 
((domain == null) ? : (; domain= + domain)) +  
((secure == true) ? ; secure : );
}
function DeleteCookie (name) { 
var exp = new Date(); 
expsetTime (expgetTime() ); 
var cval = GetCookie (name); 
okie = name + = + cval + ; expires= + exptoGMTString();
}
// End >
</SCRIPT>

</HEAD>

<BODY BGCOLOR=#ffffff vlink=#ff>

<! Demonstration >
<CENTER>
<SCRIPT LANGUAGE=JavaScript>
if (Count()==)
{
documentwrite(您好! + Who() + 您首次來這兒請多提寶貴意見);
}
else
{
documentwrite(您好! + Who() + 您已來這兒 + Count() + 次了最後一次在 + When() +);
}
</SCRIPT>
</CENTER>
</BODY>
</HTML>
From:http://tw.wingwit.com/Article/program/Java/Javascript/201311/25300.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.