![](/img/trans.png)
[英]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.