I am trying to put the cookie policies on my website but it does not work correctly. I have tried two variants and neither works correctly for me.
function GetCookie(name) {
var arg=name+"=";
var alen=arg.length;
var clen=document.cookie.length;
var i=0;
while (i<clen) {
var j=i+alen;
if (document.cookie.substring(i,j)==arg)
return "1";
i=document.cookie.indexOf(" ",i)+1;
if (i==0)
break;
}
return null;
}
function aceptar_cookies(){
var expire=new Date();
expire=new Date(expire.getTime()+7776000000);
document.cookie="cookies_surestao=aceptada; expires="+expire;
var visit=GetCookie("cookies_surestao");
if (visit==1){
popbox3();
}
}
jQuery(function() {
var visit=GetCookie("cookies_surestao");
if (visit==1){
$('#overbox3').toggle();
} else {
var expire=new Date();
expire=new Date(expire.getTime()+7776000000);
document.cookie="cookies_surestao=aceptada; expires="+expire;
}
});
function popbox3() {
$('#overbox3').toggle();
}
#overbox3 {
position: fixed;
bottom: 0px;
left: 0px;
width: 100%;
z-index: 999999;
display: block;
}
#infobox3 {
margin: auto;
position: relative;
top: 0px;
height: 58px;
width: 100%;
text-align:center;
background-color: #eeeeee;
}
#infobox3 p {
line-height:58px;
font-size:12px;
text-align:center;
}
#infobox3 p a {
margin-right:5px;
text-decoration: underline;
}
<div id="overbox3">
<div id="infobox3">
<p>Esta web utiliza cookies para obtener datos estadísticos de la navegación de sus usuarios. Si continúas navegando consideramos que aceptas su uso.
<a href="politica-privacidad.php">Más información</a>
<a onclick="aceptar_cookies();" style="cursor:pointer;">X Cerrar</a></p>
</div>
</div>
function getCookie(c_name){
var c_value = document.cookie;
var c_start = c_value.indexOf(" " + c_name + "=");
if (c_start == -1){
c_start = c_value.indexOf(c_name + "=");
}
if (c_start == -1){
c_value = null;
}else{
c_start = c_value.indexOf("=", c_start) + 1;
var c_end = c_value.indexOf(";", c_start);
if (c_end == -1){
c_end = c_value.length;
}
c_value = unescape(c_value.substring(c_start,c_end));
}
return c_value;
}
function setCookie(c_name,value,exdays){
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
if(getCookie('tiendaaviso')!="1"){
document.getElementById("barraaceptacion").style.display="block";
}
function PonerCookie(){
setCookie('tiendaaviso','1',365);
document.getElementById("barraaceptacion").style.display="none";
}
#barraaceptacion {
display:none;
position:fixed;
left:0px;
right:0px;
bottom:0px;
padding-bottom:20px;
width:100%;
text-align:center;
min-height:40px;
background-color: rgba(0, 0, 0, 0.5);
color:#fff;
z-index:99999;
}
.inner {
width:100%;
position:absolute;
padding-left:5px;
font-family:verdana;
font-size:12px;
top:30%;
}
.inner a.ok {
padding:4px;
color:#00ff2e;
text-decoration:none;
}
.inner a.info {
padding-left:5px;
text-decoration:none;
color:#faff00;
}
<div id="barraaceptacion" style="display: block;">
<div class="inner">
Solicitamos su permiso para obtener datos estadísticos de su navegación en esta web, en cumplimiento del Real
Decreto-ley 13/2012. Si continúa navegando consideramos que acepta el uso de cookies.
<a href="javascript:void(0);" class="ok" onclick="PonerCookie();"><b>OK</b></a> |
<a href="http://politicadecookies.com" target="_blank" class="info">Más información</a>
</div>
</div>
I also get the same error...
If I used something similar to yours, I would use these codes that are open source the same ( on Github ) and have several options available that, depending on the website, you can put the cookie consent in one place or another. And with this you already know that it works for sure. It is not a solution to your problem, so I am aware that I am helping you, but not to solve what you have already done programming, which is a lot. But it is a solution to this very frequent problem of the cookie issue. A solution that can work for everyone.
Perhaps this is more of a comment than an answer.
I have tried to make it an answer for everyone.