[英]Why am I getting an error when trying to add the src attribute to an img tag using JavaScript within Colfusion?
[英]Why am I getting a JavaScript compiler error when trying to publish changes to my intercom tag in Google Tag Manager?
这是我的标签:
<script>
window.intercomSettings = {
app_id: "fanwstw2"
};
</script>
<script>
(function() {
var w = window;
var ic = w.Intercom;
if (typeof ic === "function") {
ic('reattach_activator');
ic('update', intercomSettings);
} else {
var d = document;
var i = function() {
i.c(arguments)
};
i.q = [];
i.c = function(args) {
i.q.push(args)
};
w.Intercom = i;
function l() {
var s = d.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = 'https://widget.intercom.io/widget/fanwstw2';
var x = d.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s, x);
}
if (w.attachEvent) {
w.attachEvent('onload', l);
} else {
w.addEventListener('load', l, false);
}
}
})()
</script>
这是错误消息
我看不到您的代码有任何问题,也许是解析器过于笨拙。 它也可能是由您将IIFE包裹而引起的。
如何在下面更改此行(只是为了排除它的怪异)。
ic('update', intercomSettings);
为此...
ic('update', w.intercomSettings);
我也遇到了这个问题,我相信这是因为基于ES5引擎的GTM正在查看ES6代码,并试图将其解析为ES5。 它可能来自if
块中的l()
函数声明。 尝试将它移出if
块,就像之前一样,然后再次编译标签,如下所示:
(function() {
var w = window;
var ic = w.Intercom;
// moved this out of if block
function l() {
var s = d.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = 'https://widget.intercom.io/widget/fanwstw2';
var x = d.getElementsByTagName('script')[0];
x.parentNode.insertBefore(s, x);
}
if (typeof ic === "function") {
ic('reattach_activator');
ic('update', intercomSettings);
} else {
var d = document;
var i = function() {
i.c(arguments)
};
i.q = [];
i.c = function(args) {
i.q.push(args)
};
w.Intercom = i;
if (w.attachEvent) {
w.attachEvent('onload', l);
} else {
w.addEventListener('load', l, false);
}
}
})()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.