此代码将冻结Firefox 3.6。
// Google Code for Converted Users Remarketing List
function converted_remarketing() {
window.google_conversion_id = 1018522404;
window.google_conversion_language = 'en';
window.google_conversion_format = '3';
window.google_conversion_color = '666666';
window.google_conversion_label = 'e9x2CKzhXXXXpNbV5QM';
window.google_conversion_value = 0;
var a = document.createElement('script');
a.type = 'text/javascript';
a.async = true;
a.src = 'https://www.googleadservices.com/pagead/conversion.js';
var b = document.getElementsByTagName('script')[0];
b.parentNode.insertBefore(a, b);
}
converted_remarketing();
示例:http://jsfiddle.net/LLSu4/11/show/
看起来与脚本插入有关。有趣的是,我从谷歌分析代码中复制了插入片段,这些代码完美无缺。
所以问题是,为什么它冻结Firefox3.6,为什么它不冻结Firefox3.6当一个非常相似的代码运行加载谷歌分析脚本ga.js?
这显然与conversion.js中的document.write()
有关。
见http://jsfiddle.net/LLSu4/19/
ga.js不使用document.write
,因此没有问题。
在插入的脚本中使用document.write
从来不是一个好主意。这会混淆HTML引擎。你会发现bugzilla有几个关于appendChild
和document.write
的bug,例如https://bugzilla.mozilla.org/show_bug.cgi?id=607222