我正在努力在用户第一次访问我们的网站时包含 GDPR 样式/Cookie 通知,但在他们清除缓存之前不会再次访问。我设置了一个通知来显示窗口何时打开,还有一个关闭按钮来关闭它。
我尝试使用 localStorage 和 sessionStorage jquery,类似于用于帮助其他用户的那些,包括先隐藏弹出窗口然后检查 localStorage 以查看它是否存在:
$(document).ready(function() {
$('#toast').hide();
var element= localStorage.getItem('status');
if (element == null || element == '') {
localStorage.setItem('element', 1);
$('#toast').show();
}});
但是 1) 我不想复制意大利面,因为 2) 它不起作用。
这里弹出窗口的html:
<div id="toast" class="toast-close fixed-bottom" style="background-color: #DB7232; color: white; opacity: .7; margin: 0 0 2rem 2rem; padding: 1rem; width: 18rem;">
<small>By continuing to browse this site, you're accepting the use of cookies.</small>
<small><button type="button" data-dismiss="toast" class="close" aria-label="Close">×</button></small>
</div>
jquery 在此处关闭弹出窗口:
$(document).on('click', '.toast-close', function() {
$(this).fadeOut(function(){
$(this).remove();
});
});
我希望当用户第一次访问我们的网站时(或者因为我们添加了这个功能),弹出窗口就会出现;一旦他们退出弹出窗口或浏览器,通知将不会再次出现,直到他们的缓存被清除。
您正在阅读“状态”,但正在设置“元素”。这两个名字应该是一样的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句