我是javascript的菜鸟,但我需要Cookie的退出功能(数据隐私性原因)。我用Google搜索并在https://cookieconsent.insites.com/download/上找到了这个cookie-opt-out-script,并插入了回调函数 https://cookieconsent.insites.com/documentation/disabling-cookies/
但是我不确定一切是否正确,我怀疑它是否正常运行,因为浏览器仍然向我显示cookie。我如何确保它能正常工作?
感谢您的帮助!
<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.1.0/cookieconsent.min.js"></script>
<script>
window.addEventListener("load", function(){
window.cookieconsent.initialise({
"palette": {
"popup": {
"background": "#f1f1f1",
"text": "#32394b"
},
"button": {
"background": "transparent",
"text": "#32394b",
"border": "#e45468",
}
},
"position": "top",
"static": false,
"type": "opt-out",
onInitialise: function (status) {
var type = this.options.type;
var didConsent = this.hasConsented();
if (type == 'opt-in' && didConsent) {
// enable cookies
}
if (type == 'opt-out' && !didConsent) {
// disable cookies
}
},
onStatusChange: function(status, chosenBefore) {
var type = this.options.type;
var didConsent = this.hasConsented();
if (type == 'opt-in' && didConsent) {
// enable cookies
}
if (type == 'opt-out' && !didConsent) {
// disable cookies
}
},
onRevokeChoice: function() {
var type = this.options.type;
if (type == 'opt-in') {
// disable cookies
}
if (type == 'opt-out') {
// enable cookies
}
},
})});
</script>