首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过Insites使用CookieConsent中的setCookie

通过Insites使用CookieConsent中的setCookie
EN

Stack Overflow用户
提问于 2017-06-09 19:41:19
回答 2查看 3K关注 0票数 0

我正在使用Insites的CookieConsent插件,并希望在"onStatusChange“方法中使用"setCookie”函数来创建其他(其他) cookies。

代码语言:javascript
复制
onStatusChange: function(status, chosenBefore){
var type = this.options.type;
  var didConsent = this.hasConsented();

  if (type == 'opt-in' && didConsent) {
     // enable cookies


  }

}

问题是我得到“无法读取未定义的属性'setCookie‘”。任何帮助都将不胜感激。

诚挚的问候

EN

回答 2

Stack Overflow用户

发布于 2017-06-09 20:07:03

下面是我使用的插件:link

下面是我的脚本:

代码语言:javascript
复制
<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>
票数 0
EN

Stack Overflow用户

发布于 2018-11-30 05:03:25

为了在你的onStatusChange函数中创建额外的/其他cookie,尝试如下所示:

代码语言:javascript
复制
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

希望这对你有帮助!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44456878

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档