Javascript 片段冻结 Firefox3.6

发布于 2024-12-20 00:45:51 字数 1039 浏览 5 评论 0原文

此代码会冻结 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屋檐 2024-12-27 00:45:51

这显然与 conversion.js 中的 document.write() 有关。

请参阅 http://jsfiddle.net/LLSu4/19/

ga.js 不使用 document.write,因此没有问题。

在插入的脚本中使用 document.write 从来都不是一个好主意。这会让 HTML 引擎感到困惑。你会发现bugzilla有几个关于appendChilddocument.write的错误,例如https://bugzilla.mozilla.org/show_bug.cgi?id=607222

This 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 concerning appendChild and document.write, e.g. https://bugzilla.mozilla.org/show_bug.cgi?id=607222

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文