现在位置:中国IDC吧>网页设计>JavaScript教程> 文章内容

初学Javascript之cookie篇(译)

收藏发布 来源:互联网 作者:

{
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;
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 setLastlastVisitCookie ()
{
var rightNow = new Date();
var expdate = new Date();
expdate.setTime (expdate.getTime() 1 * (24 * 60 * 60 * 1000)); // 1 day
SetCookie ("lastVisit", rightNow.getTime(), expdate, "/");
}
function ResetCookie()
{
SetCookie("lastVisit", 0, null, "/");
}
// -->
</script>
</body>
</html>



上一页 1 2下一页
收藏此页到网摘/书签:
所有评论

评论列表

用户名: 新注册) 密码: 匿名评论