我正在使用Insites的CookieConsent插件,并希望在"onStatusChange“方法中使用"setCookie”函数来创建其他(其他) cookies。
onStatusChange: function(status, chosenBefore){
var type = this.options.type;
var didConsent = this.hasConsented();
if (type == 'opt-in' && didConsent) {
// enable cookies
}
}问题是我得到“无法读取未定义的属性'setCookie‘”。任何帮助都将不胜感激。
诚挚的问候
发布于 2017-06-09 20:07:03
下面是我使用的插件:link
下面是我的脚本:
<script>
window.addEventListener("load", function(){
var p;
window.cookieconsent.initialise({
"palette": {
"popup": {
"background": "rgba(255,150,33,0.9)",
"text": "black"
},
"button": {
"background": "transparent",
"border": "white",
"text": "black"
}
},
"type": "opt-in",
"content": {
message:'The message',
dismiss:'dismiss',
allow:'allow',
link:'Read more',
href:'http://example.com',
},
revokable:true,
onStatusChange: function(status, chosenBefore) {
var type = this.options.type;
var didConsent = this.hasConsented();
if (type == 'opt-in' && didConsent) {
setCookie('xxx','allow',365,'/','');
}
},
cookie: {
name: 'wwwZalarisCC'
},
onRevokeChoice: function(){
}
}, function (popup) {
p = popup;
var output = '';
for (var property in p) {
output += property + ': ' + p[property]+'; ';
}
});
document.getElementById('btn-revokeChoice').onclick = function (e) {
p.revokeChoice();
};
});
</script>发布于 2018-11-30 05:03:25
为了在你的onStatusChange函数中创建额外的/其他cookie,尝试如下所示:
onStatusChange: function(status, chosenBefore) {
var type = this.options.type;
var didConsent = this.hasConsented();
if (type === 'opt-in' && didConsent) {
document.cookie = 'cookie-name=cookie-value; expires=Thu, 31 Dec 2099 23:59:59 UTC; path=/';
}
}在这里,您可以找到更长的讨论和几个实现示例:
https://github.com/insites/cookieconsent/issues/205
希望这对你有帮助!
https://stackoverflow.com/questions/44456878
复制相似问题