<input οnclick="checkVisit('1')" type="button" value="Accept(cookie 1h)" /> //设置cookie一小时过期
function getCookie(name) {
var arg = name+ "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
var value;
var start = 0;
var end = 0;
if(clen > 0 && document.cookie.indexOf(arg) >= 0) {
start = document.cookie.indexOf(arg) + alen;
end = document.cookie.indexOf(";", start);
if(end==-1) end=clen;
value = document.cookie.substring(start, end);
return value;
}
return null;
}
function setCookie(name, value,hours) {
var date = new Date();
date.setTime(date.getTime() + hours*60*60*1000);
document.cookie = name + "=" + value + ";path=/; expires=" + date.toGMTString();
}
function delCookie(name){
var visit = getCookie("Visit");
if(visit != null){
var date = new Date();
date.setTime(date.getTime() - 2*1000);
document.cookie = name + "=" + value + ";path=/; expires=" + date.toGMTString();
}
}
function checkVisit(hours){
setCookie("Visit","true",hours);
}