This Domain(Admin5.com) is for Sale:

初学Javascript之cookie篇(译)

时间:2007-10-22  来源:不详  作者:林子

最后要说明的是,这不仅是一个专用的JS脚本,如果你想将它用在你的web页面上你必须最小程度的使用不同的浏览器测试它并注意它们的版本,许多的脚本程序包含了浏览器类型检测和大量的if...else语句,以处理这样不同。 copyright dedecms

示例页面homepage.htm源代码

本文来自织梦

<html>
<head>
<title>Homepage</title>
</head>
<body>
<a href='http://www.thehungersite.com/'>Manual redirection<br></a>
<a href="javascript:ResetCookie()">Cookie reset</a>

本文来自织梦

<script language="JavaScript">
<!--
var bVisitedToday = false;

内容来自dedecms

var lastVisit = GetCookie("lastVisit");
if (lastVisit != null)
{
lastVisit = 1 * lastVisit;
var lastHere = new Date(lastVisit);
var rightNow = new Date(); dedecms.com

if(lastHere.getYear() == rightNow.getYear()
&& lastHere.getMonth() == rightNow.getMonth()
&& lastHere.getDate() == rightNow.getDate())
{
bVisitedToday = true;
}
} 织梦内容管理系统

if(bVisitedToday == false)
{
setLastlastVisitCookie();
window.location="http://www.thehungersite.com/"
}
else
{
//window.location="about:blank"
}

织梦内容管理系统

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;

看完这篇,您有何感觉呢?

文章评论

共有位Admini5网友发表了评论 查看完整内容

24小时热门信息