我在cookie中有弹出窗口,其中包含cookie信息和js代码,可在单击按钮后将其隐藏,然后创建一个cookie,以免将来不显示弹出窗口。 它适用于android,chrom,firefox等,但不适用于Iphone和OSX。
为什么?
var box = document.getElementById('gdpr-info');
var button = document.getElementById('close');
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;
}
}
return decodeURI(dc.substring(begin + prefix.length, end));
}
var myCookie = getCookie("readed");
if (myCookie == "yes") {
box.style.display = 'none';
}
button.addEventListener('click', function() {
document.cookie = "readed=yes;";
box.style.display = 'none';
});