这是当年看着书学习修改的代码,用来控制banner的显示与否。
原理:正常情况下显示 banner,当点击关闭按钮时,通过 turnoff(obj); 函数添加一条cookie: guide_status=guide_close ,并设置 CSS display 为 none。通过 readcookie(the_info); 函数读取 cookie ,判断 guide_status=guide_close 是否存在,存在即设置 CSS display 为 none。
函数:
turnoff(obj);
function turnoff(obj){
//设置cookie过期时间,这里设为2012发生日
var the_date=new Date("December 21, 2012");
var the_cookie_date=the_date.toUTCString();
//写入cookie+过期时间
document.cookie="guide_status=guide_close;expires="+the_cookie_date;
//隐藏banner
document.getElementById(obj).style.display="none";
}
该函数以 onclick 事件插入到关闭按钮中: onclick=”javascript:turnoff(‘guidebar’)” ,guidebar 为 banner ID。