Jquery 未定义Getcookie
我正在JQuery页面中使用Jquery 未定义Getcookie,jquery,cookies,Jquery,Cookies,我正在JQuery页面中使用getcookie值。它在我所有的页面上都有效,除了一个,图书馆: 它表明: Uncaught ReferenceError: getCookie is not defined at generic-scripts.js:2 at dispatch (jquery.min.js:2) at y.handle (jquery.min.js:2) JS结构: function setAgreeCookie() { var expire=n
getcookie
值。它在我所有的页面上都有效,除了一个,图书馆:
它表明:
Uncaught ReferenceError: getCookie is not defined
at generic-scripts.js:2
at dispatch (jquery.min.js:2)
at y.handle (jquery.min.js:2)
JS结构:
function setAgreeCookie() {
var expire=new Date();
expire=new Date(expire.getTime()+777600000000);
document.cookie="COOKIESCOVID19=aceptada; expires="+expire;
}
$('#acepto-normas-seguridad').click(function(){
setAgreeCookie();
});
$(window).on('load',function(){
var myCookie = getCookie("COOKIESCOVID19");
if (myCookie == null) {
$('#modalcovid-footer').modal({backdrop: 'static', keyboard: false})
}
else {
// do cookie exists stuff
}
});
而且所有代码都在其他页面的相同结构上,因此应该可以工作,但没有。已解决,需要指定以下内容:
function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
}
else
{
begin += 2;
var end = document.cookie.indexOf(";", begin);
if (end == -1) {
end = dc.length;
}
}
// because unescape has been deprecated, replaced with decodeURI
//return unescape(dc.substring(begin + prefix.length, end));
return decodeURI(dc.substring(begin + prefix.length, end));
}
您的getCookie()
函数声明在哪里getCookie
不是jquery函数-您需要自己创建它。