html GDPR Cookie同意EU检测
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html GDPR Cookie同意EU检测相关的知识,希望对你有一定的参考价值。
<link rel="stylesheet" type="text/css"
href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.css"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.js"></script>
<script type="text/javascript" src="//js.maxmind.com/js/apis/geoip2/v2.1/geoip2.js"></script>
<script>
window.addEventListener("load", function () {
var onSuccess = function (location) {
//console.log(location.country.iso_code);
var countryCode = location.country.iso_code;
if (isEU(countryCode)) {
window.cookieconsent.initialise({
"palette": {
"popup": {
"background": "#db3e37",
"text": "#ffffff"
},
"button": {
"background": "#ffffff",
"text": "#db3e37"
}
},
"content": {
"message": "This website uses cookies to ensure you get the best experience on our website.",
"dismiss": "Got it!",
"link": "Learn more",
"href": "https://www.some-web-address.com/privacy-policy/"
}
});
}
};
var onError = function (error) {
console.log(
"Error:\n\n"
+ JSON.stringify(error, undefined, 4)
);
};
geoip2.city(onSuccess, onError);
var isEU = function (countryCode) {
euCountrycodes = [
'AT',
'BE',
'BG',
'HR',
'CY',
'CZ',
'DE',
'DK',
'EE',
'EL',
'ES',
'FI',
'FR',
'GB',
'HU',
'IE',
'IT',
'LT',
'LU',
'LV',
'MT',
'NL',
'PL',
'PT',
'RO',
'SE',
'SI',
'SK'
];
return ( inArray(countryCode, euCountrycodes) );
};
var inArray = function (needle, haystack) {
var length = haystack.length;
for (var i = 0; i < length; i++) {
if (haystack[i] == needle) return true;
}
return false;
}
});
</script>
以上是关于html GDPR Cookie同意EU检测的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 gatsby-plugin-gdpr-cookies 设置 Gatsby Cookie 同意横幅
仅为同意条款的用户存储 cookie
html GDPR Cookie控件弹出窗口
重置 GDPR/同意对话框(撤销同意后选择重新加入)
GDPR - 分析:在任何跟踪之前用户同意?
scss dFactory对GDPR的Cookie通知