设置隐私权政策通知栏,并希望每个用户或会话仅显示一次,并且仅在首页或着陆页上显示。现在,每次访问都会显示在每个页面上。
HTML
<span class="banner tracking-banner p-t-1">
<div class="container">
<div class="row">
<div class="col-sm-10 text-left m-b-1">
This website uses cookies and other 3rd party services to customize and provide you a more personalized experience. To find out more, see our <a href="/privacy/">Privacy Policy</a>.
</div>
<div class="col-sm-2 m-b-1">
<button class="dismiss btn btn-sm btn-block btn-invert">Accept</button>
</div>
</div>
</div>
</span>
JS
$(document).ready(function(){
$(".banner").fadeIn("slow").append("");
$(".dismiss").click(function(){
$(".banner").fadeOut("fast");
});
})
有没有办法添加用户或会话跟踪,以便每次都不会在每个页面上显示通知?
答案 0 :(得分:0)
请参阅会话存储:https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage
或本地存储:https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
示例:
$(document).ready(function() {
if (!sessionStorage.getItem('policy')) {
$(".banner").fadeIn("slow").append("");
$(".dismiss").click(function() {
$(".banner").fadeOut("fast");
sessionStorage.setItem('policy', 'read');
});
}
});
答案 1 :(得分:0)
使用sessionStorage临时保存显示警报的状态:
$(document).ready(function(){
if (sessionStorage.alertshown!="yes"){
$(".banner").fadeIn("slow").append("");
$(".dismiss").click(function(){
$(".banner").fadeOut("fast");
sessionStorage.alertshown="yes";
});
}
})
答案 2 :(得分:0)
要解决的几件事情:
$(document).ready(function(){
if(!sessionStorage.alertShown) {
$(".banner").fadeIn("slow").append("");
$(".dismiss").click(() => $(".banner").fadeOut("fast"));
sessionStorage.alertShown = true; //set to true so they aren't shown again
}
});