gpt4 book ai didi

jquery - cookie 指令欧盟消息。如何保存选择?

转载 作者:太空宇宙 更新时间:2023-11-03 23:10:50 24 4
gpt4 key购买 nike

我知道,有一种符合 cookie 欧盟指令的第 3 方解决方案。但我想自己学习如何做。我想要以下内容:当用户单击“接受”时,整个浏览 session 都会记住该选择。目前,每次刷新页面时都会显示该消息。谢谢,

//shows cookie message
$(document).ready(function(){

$(".cookie").toggleClass("cookieDisplayed");

//hides cookie message
$(".acceptCookies").on("click", function(){
$(".cookie").removeClass("cookieDisplayed");

});
});
.cookie {
padding:20px;
font-size:80%;
width:100%;
height:150px;
background:#F55D2D;
color:white;
position:relative;
top:-150px;

transition: top 1.5s;
-webkit-transition: top 1.5s;
-moz-transition: top 1.5s;
}

.cookie button{
margin-left:20px;
position:relative;
left:100px;
background:white;
color:#F55D2D;
border: 0;
border-radius:4px;
}

.cookie button:hover {
background:#F89576;
color:white;
}

.cookie button a {
text-decoration:none;
color:#F55D2D;
}

.cookie.cookieDisplayed {

top:0;
}
<html>
<header>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
</header>
<body>
<div class="cookie">
<p>We are using cookies to give you the best experience on our site. Cookies are files stored in your browser and are used by most websites to help personalise your web experience.</p>
<p>By continuing to use our website without changing the settings, you are agreeing to our use of cookies.</p>
<button><a href="aboutus.html">More information</a></button>
<button class="acceptCookies">Accept</button>
</div>
</body>
</html>

最佳答案

您对元素的 javascript 更改不会在重新加载后持续存在

具有讽刺意味的是,处理这种情况的最佳方法是使用 cookie。

抱歉:我的“需要一个 cookie 来确认一个 cookie”太可爱了。

localStorage是正确答案。在概念上(在欧盟法律上)cookies 和 localStorage 是相似的。两者都在用户的机器上存储了一个值——在这种情况下,他们接受了 cookie 通知——并且即使用户关闭了浏览器,它们也会持续存在。

两者是有区别的。 Cookies 起源于早期的互联网,现在用于与服务器对话。 localStorage 更适合与客户交谈。在这种情况下,两者都可以工作(但本地存储会更容易)。

sessionStorage 仅在用户关闭浏览器之前一直存在。

关于jquery - cookie 指令欧盟消息。如何保存选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32620110/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com