Search code examples
javascriptgoogle-website-optimizer

Do JavaScript problems break the browser?


I'm running Google Website Optimizer, and its executing client-side cookie checks to show content just once.

However, when they're cookied, I get a javascript error that doesn't SEEM fatal, but I've read that 1 js error is enough to totally break Internet Explorer.

the line of code in question is <script>utmx_section("Blah")</script>

This line is provided directly by Google, but I get an error that is not defined. Now, it runs at the very bottom of the page, so the worst case is that GA doesn't run.

But what are the hazards?


EDIT: I wasn't directly asking to debug my JS, because the problem is esoteric and it's possible its due to a mistake or an erroneous assumption. The question was whether it was hazardous to ignore the problem.

The error I get is: "utmx_section is not defined", even though the JavaScript that provides the function in question is properly included, and the only difference between the pages that it does throw an error on and those that it doesn't is that some extra JQuery is run (due to a conditional that checks for a cookie) on the pages that it doesn't throw an error.

FURTHER EDIT: Got around the problem by having a PHP conditional execute the utmx line only when it would be needed (ie, on un-cookied users).


Solution

  • Most users have JavaScript notifications turned off so they wouldn't see the error. The error will not "break the browser" in your case; where it does break is subsequent calls to that function and any code after that call within that script block:

    utmx_section("Blah");
    // later:
    utmx_section("Correct"); <-- will not fire
    

    and:

    utmx_section("Blah"); 
    var a = b; <-- will not fire
    doStuff(); <-- will not fire
    

    Fixing this in PHP was doing it the hard way. Just add a conditional. And you have to use "window" when looking to see if a global variable exists:

    if(window.utmx_section){
        utmx_section("Blah");
    }