始终显示带有cookie的信息框
Information box with cookie will be displayed all the time
这就是为什么当我点击我的按钮,所以重新加载页面,我可以记住看起来像框"走开了,当我点击。但是当我点击的时候,它没有设置cookie,它也没有检查是否设置?
所以现在的问题是:
- Cookie不会添加
- 不检查我们今天的日期比我们有cookie的日期多10天换句话说,在显示内容之前再走10天。
我在asp.net中使用web表单
Html代码
<div style="position: relative;" id="#CookieBox">
<div class="alert alert-info fade in nomargin" style="margin: 0; position:fixed; bottom:0; right:0; left:0; height:65px; border-radius:0; z-index:10000;">
<div class="container">
<p style="font-size:11px;">
Cookies er nødvendige for at få hjemmesiden til at fungere, men cookies giver også info om hvordan du bruger vores hjemmeside. og Cookies på denne hjemmeside bruges primært til trafikmåling
<button class="btn btn-info" id="AccepterCookie">Accepter</button>
<a href="../cookie/Cookies.pdf" target="_blank">Læs mere</a>
</p>
</div>
</div>
</div>
Jquery代码在这里
<script>
var datoCookieValue = (new Date).setDate(10); //This cookie number of days
//It must check in sf whether it is null or whether it is more than the 10 days that I have chosen.
if (datoCookieValue == null || datoCookieValue >= (new Date).getDay)//checking up on whether the cookie is "set"
{
//when you click "Accept" so be content with cookie box contents go away
$("#AccepterCookie").click(function () {
$("#CookieBox").slideDown("slow");//shuts down the cookie box.
//addcookie here
$.cookie("CookieAdd", 1, { expires: datoCookieValue });
});
}
else
{
//must first show box on the 10 days it will look when the
//10 days are up then the display contents again.
$("CookieBox").hide("fast");
}
</script>
在jquery中有时使用#CookieBox和CookieBox选择器。如果你检查日期的条件在我看来是不必要的,因为cookie有一个到期时间。
这是我的解决方案:
<div style="position: relative; display:none" id="CookieBox">
<div class="alert alert-info fade in nomargin" style="margin: 0; position:fixed; bottom:0; right:0; left:0; height:65px; border-radius:0; z-index:10000;">
<div class="container">
<p style="font-size:11px;">
Cookies er nødvendige for at få hjemmesiden til at fungere, men cookies giver også info om hvordan du bruger vores hjemmeside. og Cookies på denne hjemmeside bruges primært til trafikmåling
<button class="btn btn-info" id="AccepterCookie">Accepter</button>
<a href="../cookie/Cookies.pdf" target="_blank">Læs mere</a>
</p>
</div>
</div>
</div>
jQuery: var datoCookieValue = $.cookie('CookieAdd');
if (!datoCookieValue) {
$("#CookieBox").show();
$("#AccepterCookie").click(function() {
$("#CookieBox").hide("slow");
$.cookie("CookieAdd", 1, {
expires: 10
});
});
}
JS Fiddle: https://jsfiddle.net/cLtazsry/
相关文章:
- 访问布局信息是否也会导致浏览器重排
- 在jquery中为显示/隐藏设置cookie
- 按下按钮时保存cookie
- 定义完全独立的样式信息
- 试图用cookie中的信息填充表单
- Javascript - 预填充 cookie 信息,以在指向外部站点的链接上交叉传递不必要的登录页面
- 如何使用 Cookie 将信息保存在输入标签中
- 当请求一个JS文件时,为什么需要cookie信息(会话ID)
- 如何保存cookie信息
- 谷歌分析-媒体信息从cookie成功的交易
- 目前接受的在浏览器窗口中处理客户端会话信息的无cookie方法
- 始终显示带有cookie的信息框
- 使用cookie来存储当前网页的信息
- 提取谷歌分析活动Cookie信息,并插入查询表单字段.这可能吗?
- 打印存储为cookie和session php的个人信息
- 在cookie中存储信息
- 使用ETag在浏览器中存储cookie信息
- cookie、localStorage和jquery数据用于存储大小和位置信息
- Wordpress的cookie法律信息插件出错
- 验证Cookie是否存在并存储信息