如果接受则不会再次显示 Cookie 同意弹出窗口
假设用户单击 cookie 同意弹出窗口中的“接受”链接,则该弹出窗口不应在 24 小时内再次显示。有人可以告诉我如何完成这件事吗?
<div id="cookieConsent">
<div id="closeCookieConsent">x</div>
This website is using cookies. <a href="cookies-policy" target="_blank">More info</a>. <a class="cookieConsentOK"><b>ACCEPT</b></a>
</div>
$(document).ready(function() {
setTimeout(function() {
$("#cookieConsent").fadeIn(200);
}, 4000);
$("#closeCookieConsent, .cookieConsentOK").click(function() {
$("#cookieConsent").fadeOut(200);
});
});
Supposing the user clicks the 'ACCEPT' link in the cookie consent popup, then the popup should not show again for 24hrs. Can someone show how me how to get this done?
<div id="cookieConsent">
<div id="closeCookieConsent">x</div>
This website is using cookies. <a href="cookies-policy" target="_blank">More info</a>. <a class="cookieConsentOK"><b>ACCEPT</b></a>
</div>
$(document).ready(function() {
setTimeout(function() {
$("#cookieConsent").fadeIn(200);
}, 4000);
$("#closeCookieConsent, .cookieConsentOK").click(function() {
$("#cookieConsent").fadeOut(200);
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对您的代码进行了一些更改,以存储一个值为 true 的本地变量,并且从用户单击“接受”时起,过期时间为 10 秒。将此部分更改为如下内容:
now.getTime() + (1000 * 60 * 60 * 24)
每次加载页面时,脚本都会查找此存储的变量,以及过期时间是否大于存储的值然后删除存储的变量并再次显示 cookie 接受消息。
这里是代码:
I have changed a little bit your code to store a local var with a value of true and expiration time of 10 seconds from the moment when user click on ACCEPT. Change this part to something like:
now.getTime() + (1000 * 60 * 60 * 24)
Every time page is loaded the script look for this stored var and if the expiration time is greater than the stored value then delete the stored var and show the cookie acceptance message again.
Here the code: