views:

75

answers:

3

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).

A: 

I'm not exactly sure what you mean by "when they're cookied"
However, yes, a piece of javascript will generally cause further javascript processing to halt.

Regardless, you should debug the problem. The google analytics code works on a tremendous number of sites, so I'm guessing you actually have a problem elsewhere. Either in how you copied the code, dependencies, or in some of yours which is filtering down.

Chris Lively
Should have been clearer: The broken code is Google Website Optimizer; the only code that runs after the problem is Google Analytics code.
yc
+2  A: 

To respond strictly to the question in the title "Do JavaScript problems break the browser?", some do.

Consider the following:

<script type="text/javascript">
  function doSomething() {
     //some stuff here
  }      
  for (;;) {
    doSomething();
  }

</script>

Not all browser are smart enough to detect this sort of issue. This will hang your browser so you have to go killer on its process.

Newer browsers detect it and display a notification allowing your to kill the script in the browser, but as I said, not all are smart enough.

As to the body of your question, not sure what the issue with <script>utmx_section("Blah")</script> is. Could you provide more details?

dpb
Provided some more details in my edit. Thanks for the (patient) answer! :)
yc
+1  A: 

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");
}
mwilcox