為了簡單了解一下Cookie讀寫的原理
寫Cookie
< script >
function setCookie()
//建立設定Cookie的函數
{ var the_visits =
//初始化VISIT
var the_cookie =
+ escape(the_visits);
//加入自己的標識符
okie = the_cookie;//寫入Cookie
}
< /script >
讀Cookie
< script >
function readCookie()
{ var the_cookie = okie;
//獲得已寫的Cookie值
var broken_cookie = the_cookie
//找出分隔符
var the_visits = broken_cookie[
//讀出分隔符後一部分
var the_visits = unescape(the_visits);
//用unescape函數對Cookie解碼
document
+ the_visits); //寫出訪問次數
}
< /script >
這樣
讀Cookie
< script >
function readCookie()
{ var the_cookie = okie;
//獲得已寫的Cookie值
var broken_cookie = the_cookie
//找出分隔符
var the_visits = broken_cookie[
//讀出分隔符後一部分
var the_visits = unescape(the_visits);
//用unescape函數對Cookie解碼
document
+ the_visits); //寫出訪問次數
}
< /script >
最後在網頁中加入
但
< html >
< script Language=
function GookieVal(offset)
//獲得Cookie解碼後的值
{
var endstr = okie
indexOf (
if (endstr ==
endstr = okie
return unescape(okie
substring(offset
}
function Gookie(name)
//獲得Cookie的原始值
{ var arg = name +
var alen = arg
var clen = okie
var i =
while (i < clen)
{
var j = i + alen;
if (okie
substring(i
return GookieVal (j);
i = okie
if (i ==
}
return null;
}
function Sookie(name
//設定Cookie值
{ var argv = Sookie
var argc = Sookie
var expires = (argc >
var path = (argc >
var domain = (argc >
var secure = (argc >
okie = name +
escape (value) +((expires == null) ?
+((path == null) ?
(
: (
+((secure == true) ?
}
function Dookie(name)
{ var exp = new Date();
exp
var cval = Gookie (name);
okie = name +
expires=
}
< /script >
< script >
var expdate = new Date();
expdate
(
if(!(visits = Gookie(
{ visits =
Sookie(
document
else{ visits++;
Sookie(
document
}
if(visits<
document
if(visits >=
document
if(visits >=
document
if(visits >=
document
< /script >
< /html >
在判斷訪問次數所表達的句子上
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19349.html