【问题标题】:Disable cookies until consented在同意之前禁用 cookie
【发布时间】:2018-12-18 19:54:44
【问题描述】:

在用户同意之前,我正在尝试禁用 cookie。我的网站上没有很多 cookie,唯一可能收集一些“个人数据”的 cookie 是由谷歌分析添加的。

Google Analytics 提供了以下脚本来禁用其 cookie:

窗口['ga-disable-UA-xxxxxxxx-y'] = true;

但这只是删除了_ga _gat _gid。我也在尝试找到一种方法来删除这些:

gadwp_wg_default_dimension,

gadwp_wg_default_metric,

gadwp_wg_default_swmetric

另外,一些 cookie 是由第三方设置的,例如 _biz_dfsA、_biz_nA 是由 cloudfare 设置的。

有没有办法只知道它的名字就禁用特定的cookie?

谢谢。

【问题讨论】:

    标签: javascript php cookies


    【解决方案1】:

    我不确定你是否可以阻止它们被设置,但你可以检查它们是否被设置:

    if (document.cookie.split(';').filter(function(item) {
        return item.indexOf('reader=') >= 0
    }).length) {
        console.log('The cookie "reader" exists')
    }
    

    //ES2016

    if (document.cookie.split(';').filter((item) => item.includes('reader=')).length) {
        console.log('The cookie "reader" exists')
    }
    

    然后删除:

    document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
    

    https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-17
      • 1970-01-01
      • 1970-01-01
      • 2019-12-23
      • 1970-01-01
      相关资源
      最近更新 更多