Javascript 片段冻结 Firefox3.6
此代码会冻结 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/
看起来像这样与脚本插入有关。有趣的是,我从 Google Analytics 代码中复制了插入片段,效果完美。
所以问题是,为什么它会冻结 Firefox 3.6,为什么当运行非常相似的代码来加载 Google Analytics 脚本 ga.js 时它不会冻结 Firefox3.6?
This code is freezing 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();
Example page: http://jsfiddle.net/LLSu4/11/show/
Looks like it has something to do with the script insertion. The funny thing is that I copied the insertion snippet from Google Analytics code that works flawlessly.
So the question is, why is it freezing Firefox 3.6 and why it doesn't freeze Firefox3.6 when a very similar code is ran to load Google Analytics script ga.js?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这显然与 conversion.js 中的
document.write()
有关。请参阅 http://jsfiddle.net/LLSu4/19/
ga.js 不使用
document.write
,因此没有问题。在插入的脚本中使用
document.write
从来都不是一个好主意。这会让 HTML 引擎感到困惑。你会发现bugzilla有几个关于appendChild
和document.write
的错误,例如https://bugzilla.mozilla.org/show_bug.cgi?id=607222This is apparently related to a
document.write()
in conversion.js.See http://jsfiddle.net/LLSu4/19/
ga.js does not use
document.write
, hence no problem there.Using
document.write
in an inserted script is never a good idea. This will confuse the HTML engine. You'll find that bugzilla has several bugs concerningappendChild
anddocument.write
, e.g. https://bugzilla.mozilla.org/show_bug.cgi?id=607222