javascript 24小时弹出一次的代码(利用cookies)


复制代码 代码如下:

function phpstudytuitan(){
if (getCookie('phpstudypopped')==''){
//要执行的代码或一些操作
setCookie("phpstudypopped","ok"); //写入cookies表示已经执行过了。
alert("ok");
}
}
phpstudytuitan()
function setCookie(name, value)
{
var argv = setCookie.arguments;
var argc = setCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
if(expires!=null)
{
var LargeExpDate = new Date ();
LargeExpDate.setTime(LargeExpDate.getTime() + (expires*1000*3600*24));
}
document.cookie = name + "=" + escape (value)+((expires == null) ? "" : ("; expires=" +LargeExpDate.toGMTString()));
}

function getCookie(Name)
{
var search = Name + "="
if(document.cookie.length > 0)
{
offset = document.cookie.indexOf(search)
if(offset != -1)
{
offset += search.length
end = document.cookie.indexOf(";", offset)
if(end == -1) end = document.cookie.length
return unescape(document.cookie.substring(offset, end))
}
else return ""
}
}

把想要输出的内容,放到phpstudytuitan()函数里面的判断语句里面即可。
« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3