js制作提示公告带关闭可保存cookie | 无涯博客

当前位置: 首页 >> 网络技巧 >> 正文contribute

js制作提示公告带关闭可保存cookie

无涯在网上看到这个,感觉还不错,记录下以备后用。

你喜欢的话,也尽可拿去使用。

此代码加工了一下以前的提示公告,加了cookie,演示当中如果点了关闭按钮,那么12小时之内都不会显示提示。

点击可观看演示

html代码

<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″ />
<meta name=”Copyright” content=”无涯博客 http://www.wuyablog.cn/” />
<meta name=”description” content=”无涯博客- 博客赚钱!” />
<meta content=”无涯博客” name=”keywords” />
<title>网页顶部浮动横条公告栏/提示信息(带关闭可保存cookie) www.wuyablog.cn</title>
<style type=”text/css”>
<!–
body { margin: 0px;padding: 0px;text-align: center;}
TD {FONT-SIZE: 12px; COLOR: #333;}
#toubiao {BORDER-BOTTOM: #808080 1px solid;background-color:#ffffe1;display:none}
–>
</style>
</head>

<body>

<SCRIPT>
function toueme(){
document.getElementById(“toubiao”).style.display=”none”;
addCookie(‘geekso’,'xiaolin’,12);
}

function addCookie(objName,objValue,objHours) {
var str = objName + “=” + escape(objValue);
if(objHours > 0){
var date = new Date();
var ms = objHours*3600*1000;
date.setTime(date.getTime() + ms);
str += “; expires=” + date.toGMTString();
}
document.cookie = str;
}

function getCookie(objName) {
var arrStr = document.cookie.split(“; “);
for(var i = 0;i < arrStr.length;i ++){
var temp = arrStr[i].split(“=”);
if(temp[0] == objName) return unescape(temp[1]);
}
}
function show_gg()
{
t = getCookie(‘geekso’);
if (t != ‘xiaolin’)
{
document.getElementById(“toubiao”).style.display=”block”;
}
}
</SCRIPT>

<DIV id=toubiao>
<table width=”100%” border=”0″ cellspacing=”0″ cellpadding=”0″>
<tr>
<td width=”4%” height=”30″ align=”center”>&nbsp;</td>
<td width=”82%”>公告:欢迎光临无涯博客,此博客主要关注互联网,关注博客赚钱。</td>
<td width=”14%” align=”right”><a style=”CURSOR: hand” onClick=toueme()><img
src=”http://a1080016.vip150.2hezu.com/tupian/close.gif” width=14 height=14 hspace=”6″ border=0 title=”关闭”></a></td>
</tr>
</table>
</DIV>
<script>
show_gg();
</script>
</body>
</html>

注意,此代码首次运行后,12小时内不再显示。所以当你观看演示并关闭之后,再点击观看演示的话,他是不会再出现的了。

  转载请注明来源:无涯博客-《js制作提示公告带关闭可保存cookie》
  本文链接地址:http://www.wuyablog.cn/?p=318

0 条评论 发表评论

留下回复

香港六合彩 香港六合彩 香港六合彩