Javascript Cookie通知wordpress插件需要简单修改

Need simple modification for Javascript Cookie notice wordpress plugin

我按照 tutorial 为我的 wordpress 网站创建 cookie 通知弹出窗口,它按预期工作,我不擅长 javascript,所以我想在用户点击 [=11] 后=] 按钮并接受 cookie,将自动重定向到与 ?ok=3 query

相同的页面

<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>

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

无论如何,解决方案是:

添加,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,特别是代码看起来更小。