您的位置:首页 > 其它

设置、删除cookie实现关闭一个层后,即使刷新也不会再显示

2011-12-08 16:44 253 查看
<html>
<head>
<title>
关闭一个层后,即使刷新也不会再显示,除非退出网页重新登录
</title>
<script type="text/javascript">
function close() {
var wel = document.getElementById("ctl00_ContentPlaceHolder1_welcome");
wel.parentNode.removeChild(wel);
//document.getElementById("flag").value = "1";
document.cookie = "close";
//wel.style.z-index="1";
}
// window.onload = function() { //这样写div总是闪一下才消失
// var str = document.cookie;
// if (str.indexOf("close") > -1) {
// close();
// }
// }
</script>
</head>
<body>
<div runat="server" id="welcome" style="display: none; position: fixed; top: 300px;
left: 650px; z-index: 100; background-color: Red;">
</div>
</body>
</html>
***********************************************
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["close"] != null) return;
string username = Session["sen"].ToString().Split('-')[1].ToString();
string[] vips = ConfigurationManager.AppSettings["vip"].ToString().Split(',');
if (vips.Contains(username))
{
welcome.Style.Add("display", "");
welcome.InnerHtml = "尊敬的VIP用户" + username + ",欢迎光临本网站!<a href='javascript:close();'>Ⅹ</a>";
}
}
************************************************
设置cookie:HttpCookie mycookie=new HttpCookie ("close2");
Response.Cookies.Add(mycookie);
删除cookie:HttpCookie mycookie = new HttpCookie("close2");
mycookie.Expires = DateTime.Now.AddHours(-24);
Response.Cookies.Add(mycookie);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐