Javascript snippet freezes Firefox3.6

This code freezes 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/

It looks like this has something to do with the insert script. The funny thing is that I copied the paste fragment from the Google Analytics code, which works flawlessly.

So the question is, why does it freeze Firefox 3.6 and why does it not freeze Firefox3.6 when very similar code is run to load the Google Analytics script ga.js?

+4
source share
1 answer

This is apparently related to document.write() in conversion.js.

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

ga.js does not use document.write , so there is no problem.

Using document.write in an inserted script is never a good idea. This will confuse the HTML engine. You will find that bugzilla has several errors regarding appendChild and document.write , for example. https://bugzilla.mozilla.org/show_bug.cgi?id=607222

+4
source

Source: https://habr.com/ru/post/1385253/


All Articles