2011-12-08 37 views
4

此代碼凍結Firefox 3.6。JavaScript snippet freeze Firefox3.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/

看起來它有事情做與腳本插入。有趣的是,我從谷歌分析代碼複製了插入片段,完美地工作。

所以問題是,爲什麼它凍結Firefox 3.6以及爲什麼它不凍結Firefox3.6當一個非常類似的代碼運行加載谷歌分析腳本ga.js?

+0

你應該將什麼參數傳遞給方法? –

+0

@MyHeadHurts它並不重要。我刪除它使其更容易。仍然凍結。 – Eduardo

+1

爲什麼現在還有人會使用FF3.x? – ThiefMaster

回答

4

這顯然與conversion.js中的document.write()有關。

http://jsfiddle.net/LLSu4/19/

的ga.js不使用document.write,也因此沒有問題。

在插入的腳本中使用document.write從來就不是一個好主意。這會混淆HTML引擎。你會發現bugzilla有幾個bug,如appendChilddocument.write,例如https://bugzilla.mozilla.org/show_bug.cgi?id=607222

+0

所以一個可能的解決方案是用另外的東西來覆蓋document.write,就像你在那個小提琴中做的那樣? – Eduardo

+0

是的。 img是典型的跟蹤像素,因此您不妨使用DOM方法插入它而不會丟失功能。然而,一個通用的解決方案非常棘手。你要麼必須在JS中解析標記,要麼通過documentFragment或隱藏的iFrame等使用瀏覽器的解析器。後者無法保證工作:我的一位同事在IE和Flash內容方面存在問題。 – user123444555621