电脑技术学习

一个IP只提示一次设为首页

dn001

把以下代码加入到<head></head>之间

<script>
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = documents.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (documents.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = documents.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;
documents.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);
// This cookie is history
var cval = 0;
documents.cookie = name + "=" + cval + "expires=" + exp.toGMTString();
}

//设置cookies时间,自己根据情况设置。
var expDays = 1;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function amt(){
var count = GetCookie('count'); //同一ip只显示一次
//var count;//同一ip只显示N次
//alert(count);
//count = null;
if(count == null) {
SetCookie('count','1')
return 1
}
else{
var newcount = parseInt(count) + 1;
if(newcount<2) count=1;
SetCookie('count',newcount,exp);
//DeleteCookie('count')
return newcount
}
}

function getCookieVal(offset) {
var endstr = documents.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = documents.cookie.length;
return unescape(documents.cookie.substring(offset, endstr));
}
function sethome(){
document.links[0].style.behavior='url(#default#homepage)';
document.links[0].setHomePage('http://www.***.com');
}
if(amt()==1)
{
sethome()
}
//-->
</script>