gpt4 book ai didi

javascript - 如何将 data-cookieconsent ="statistics"添加到脚本标记?

转载 作者:行者123 更新时间:2023-12-03 01:46:59 26 4
gpt4 key购买 nike

在我的 WordPress 网站上,我使用的插件创建了一个脚本。这是插件的片段。

<!-- Start of Async Drift Code -->
<script>
"use strict";

!function() {
var t = window.driftt = window.drift = window.driftt || [];
if (!t.init) {
if (t.invoked) return void (window.console && console.error && console.error("Drift snippet included twice."));
t.invoked = !0, t.methods = [ "identify", "config", "track", "reset", "debug", "show", "ping", "page", "hide", "off", "on" ],
t.factory = function(e) {
return function() {
var n = Array.prototype.slice.call(arguments);
return n.unshift(e), t.push(n), t;
};
}, t.methods.forEach(function(e) {
t[e] = t.factory(e);
}), t.load = function(t) {
var e = 3e5, n = Math.ceil(new Date() / e) * e, o = document.createElement("script");
o.type = "text/plain", o.crossorigin = "anonymous", o.async = !0, o.src = "https://js.driftt.com/include/" + n + "/" + t + ".js";
var i = document.getElementsByTagName("script")[0];
i.parentNode.insertBefore(o, i);
};
}
}();
drift.SNIPPET_VERSION = '0.3.1';
drift.load('33xndb9yn9ha');
</script>
<!-- End of Async Drift Code -->

我想为 CookieBot 启用此脚本的事先同意为此,脚本应如下所示

<script type="text/plain" data-cookieconsent="statistics" src="where/ever"></script>

我尝试简单地使用 o.data-cookieconsent="statistics 添加它,如下所示:

   <!-- Start of Async Drift Code -->
<script>
"use strict";

!function() {
var t = window.driftt = window.drift = window.driftt || [];
if (!t.init) {
if (t.invoked) return void (window.console && console.error && console.error("Drift snippet included twice."));
t.invoked = !0, t.methods = [ "identify", "config", "track", "reset", "debug", "show", "ping", "page", "hide", "off", "on" ],
t.factory = function(e) {
return function() {
var n = Array.prototype.slice.call(arguments);
return n.unshift(e), t.push(n), t;
};
}, t.methods.forEach(function(e) {
t[e] = t.factory(e);
}), t.load = function(t) {
var e = 3e5, n = Math.ceil(new Date() / e) * e, o = document.createElement("script");
o.type = "text/plain", o.crossorigin = "anonymous", o.async = !0, o.data-cookieconsent="statistics", o.src = "https://js.driftt.com/include/" + n + "/" + t + ".js";
var i = document.getElementsByTagName("script")[0];
i.parentNode.insertBefore(o, i);
};
}
}();
drift.SNIPPET_VERSION = '0.3.1';
drift.load('33xndb9yn9ha');
</script>
<!-- End of Async Drift Code -->

但是我在控制台中收到此错误: Uncaught ReferenceError :赋值中的左侧无效非常感谢任何关于我做错了什么或如何正确添加 data-cookieconsent="statistics"的指导。

最佳答案

Charlietfl 在评论中提到问题是点符号名称中不能有“-”。有关点表示法和语法的更多信息 Here: MDN Web Docs

所以这个:

o.data-cookieconsent="statistics"

应该写成:

o['data-cookieconsent']='statistics'

关于javascript - 如何将 data-cookieconsent ="statistics"添加到脚本标记?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50594515/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com