加载脚本并在链接触发时执行

发布于 2025-01-19 07:54:49 字数 738 浏览 1 评论 0原文

我在所有页面上都有一个cookie横幅加载,我想防止脚本在隐私政策页面上加载。但是需要脚本来访问cookie设置。 加载cookie横幅和此脚本需要的主要脚本

<script src="lib/js/cookieconsent.js"></script>

启动了cookie横幅。

<script>
    function f1() {
        let loadCookie2 = document.createElement("script");
        loadCookie2.type = "text/javascript";
        loadCookie2.setAttribute("src", "lib/js/cookieconsent-init.js");
        document.body.appendChild(loadCookie2);
    }
</script>

触发设置的链接

&lt; a href =“ javascript:f1();” type =“ button” data-cc =“ c-settings”&gt; cookie设置&lt;/a&gt;

data-cc =“ c-settings”加载cookie设置,以及当我单击链接首先加载脚本,然后单击后,它显示了设置。

如何防止我可以同时触发它们?

I have a cookie banner loading on all pages and I want to prevent the script from loading on the Privacy Policy page. But the script is needed to access the cookies settings.
Main scripts that needed to load the cookie banner

<script src="lib/js/cookieconsent.js"></script>

and this script initiate the cookie banner.

<script>
    function f1() {
        let loadCookie2 = document.createElement("script");
        loadCookie2.type = "text/javascript";
        loadCookie2.setAttribute("src", "lib/js/cookieconsent-init.js");
        document.body.appendChild(loadCookie2);
    }
</script>

the link that triggers the settings

<a href="javascript:f1();" type="button" data-cc="c-settings">cookie settings</a>

data-cc="c-settings" loads the cookie settings, and when I click on the link it first loads the script and after a second click it shows the settings.

How to prevent that can I trigger them simultaneously?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静谧 2025-01-26 07:54:49

在@cbroe评论的帮助下,这是解决方案
在配置文件中。 cookieConsent-init.js

uncomment autorun并添加

autorun = window.location !== "privacy" //this should be the privacy url

With the help of @CBroe comment this is the solution
In the configuration file. cookieconsent-init.js

uncomment autorun and add

autorun = window.location !== "privacy" //this should be the privacy url
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文