Another Reason I Hate Internet Explorer

January 23rd, 2008 by Andrew

I’ve never calculated it, but if I had to guess, I’d say I spend 30% of my time designing a site, 30% implementing the site, and 40% fixing it up so it will work in Internet Explorer. This goes for CSS and Javascript. I recently discovered mootools, a nice Javascript framework with some cool effects. In the past I have also used script.aculo.us, but I wanted to try something new. So while writing some new code for Mootools, I discovered that the Javascript worked fine in Firefox (of course), Safari, etc., but Internet Explorer 6 and 7 died on it. Here’s an example:

var Site = {
 
	start: function() {
 
  	  if ($('givenow')) Site.giveNow();
 
	},
 
	giveNow: function(){
 
		var size_closed = 56;
		var size_open = 110;
 
		var gn = $('givenow-a');
 
		var fx = new Fx.Styles(gn, {wait: false, duration: 300, transition: Fx.Transitions.Quad.easeOut});
 
		gn.addEvent('mouseenter', function(){
			fx.start({'width': size_open});
		});
 
		gn.addEvent('mouseleave', function(){
			fx.start({'width': size_closed});
		});
 
	},
 
};

Can you see what’s wrong with that code? I couldn’t see it for about 30 minutes. IE kept giving the error “expected identifier, string or number”, and pointed to the last line of the script as the problem location. Well, the last line looked fine to me.

What it ended up being was the final comma after the function giveNow. Huh? Well, it seems that when grouping functions like this in an object, the last function shouldn’t have a comma after it. Firefox and everything else handled it just fine. Internet Explorer decided it wouldn’t run any of my Javascript code after seeing that. Thanks for making life wonderful, Internet Explorer.

Comments

One Response to “Another Reason I Hate Internet Explorer”

  1. Thank you Andrew! I’ve been searching for hours to find this absurd bug :-!

Leave a Reply