4

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?

Eduardo
  • 21,340
  • 11
  • 72
  • 92

1 Answers1

4

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

user123444555621
  • 130,762
  • 25
  • 104
  • 122
  • So a possible solution would be to overwrite document.write with something else, like you did in that fiddle? – Eduardo Dec 11 '11 at 02:06
  • Yes. That img is typical tracking pixel, so you might as well insert it using DOM methods without losing functionality. However, a general solution is pretty tricky. You'd either have to parse markup in JS or use the browser's parser via documentFragment or a hidden iFrame or such. The latter is not guaranteed to work: A colleague of mine had issues with IE and Flash content. – user123444555621 Dec 11 '11 at 08:00