【问题标题】:Need simple modification for Javascript Cookie notice wordpress plugin需要对 Javascript Cookie 通知 wordpress 插件进行简单修改
【发布时间】:2022-02-12 23:55:25
【问题描述】:

我按照tutorial 为我的wordpress 网站创建cookie 通知弹出窗口,它按预期工作,我不擅长javascript,所以我希望在用户点击X 按钮并接受cookie 后自动使用?ok=3 查询重定向到同一页面

<script>cookieLaw={dId:"cookie-law-div",bId:"cookie-law-button",iId:"cookie-law-item",show:function(e){if(localStorage.getItem(cookieLaw.iId))return!1;var o=document.createElement("div"),i=document.createElement("p"),t=document.createElement("button");i.innerHTML=e.msg,t.id=cookieLaw.bId,t.innerHTML=e.ok,o.id=cookieLaw.dId,o.appendChild(t),o.appendChild(i),document.body.insertBefore(o,document.body.lastChild),t.addEventListener("click",cookieLaw.hide,!1)},hide:function(){document.getElementById(cookieLaw.dId).outerHTML="",localStorage.setItem(cookieLaw.iId,"1")}},cookieLaw.show({msg:"We use cookies to give you the best possible experience. By continuing to visit our website, you agree to the use of cookies as described in our <a href='#'>Cookie Policy</a>",ok:"x"});</script>

【问题讨论】:

  • 我的问题有什么问题,我没有帮我解决问题,而是发现有人给我负面评价,如果你不知道答案也没关系,但是为什么这个负面评价?! !

标签: javascript wordpress redirect cookies


【解决方案1】:

虽然我觉得有些人没有帮助我解决我的问题,但他们决定给我负利率,这让我感到难过。但我会分享解决我的问题的解决方案,以防其他人面临同样的问题,问题不在于找到导航到网页location.href 的 JS 代码,问题是我应该在哪里添加它这个缩小的代码。

无论如何,解决办法是:

添加,location.href = window.location.href+"?ok=3";

localStorage.setItem(cookieLaw.iId,"1"),之后

}},cookieLaw.show({之前

所以最终的代码是:

<script>cookieLaw={dId:"cookie-law-div",bId:"cookie-law-button",iId:"cookie-law-item",show:function(e){if(localStorage.getItem(cookieLaw.iId))return!1;var o=document.createElement("div"),i=document.createElement("p"),t=document.createElement("button");i.innerHTML=e.msg,t.id=cookieLaw.bId,t.innerHTML=e.ok,o.id=cookieLaw.dId,o.appendChild(t),o.appendChild(i),document.body.insertBefore(o,document.body.lastChild),t.addEventListener("click",cookieLaw.hide,!1)},hide:function(){document.getElementById(cookieLaw.dId).outerHTML="",localStorage.setItem(cookieLaw.iId,"1"),location.href = window.location.href+"?ok=3";}},cookieLaw.show({msg:"We use cookies to give you the best possible experience. By continuing to visit our website, you agree to the use of cookies as described in our <a href='#'>Cookie Policy</a>",ok:"x"});</script>

也许解决方案很简单,但正如我所提到的,我擅长 javascript,特别是代码看起来被缩小了。

【讨论】:

    猜你喜欢
    • 2018-05-23
    • 2021-12-21
    • 2015-12-05
    • 2020-11-07
    • 1970-01-01
    • 1970-01-01
    • 2011-03-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多