Tuesday, June 21, 2011

IE6 JavaScript fragility

I've always considered myself lucky to have very little to do with IE6. This is partly because I'm not a web designer and partly because so far I've worked on projects that either have a great deal of control over which browser is used, or ones that didn't care about IE6.

Now though, I'm working for this company, and a lot of our employees work for other companies as well, and they often don't have any other choice than IE6. So now I need to start minding it.
So far I've only really had to deal with parts of the application that people at our office use, and they all use Chrome there, so I've had an easy ride. Now though I'm entrenched in a part that employees have to use as well and immediately things go wrong.

I was unaware that IE6's JavaScript parser is so picky that it doesn't allow left-over commas in arrays.
So this is ok:
$(".datepicker").datepicker({
  showOn:          "both",
  buttonImage:     "images/calendar.png",
  buttonImageOnly: true,
  changeMonth:     true,
  changeYear:      true,
  yearRange:       '1900:+20'
});
But this:
$(".datepicker").datepicker({
  showOn:          "both",
  buttonImage:     "images/calendar.png",
  buttonImageOnly: true,
  changeMonth:     true,
  changeYear:      true,
  yearRange:       '1900:+20',
});
Doesn't actually seem to generate an error in IE6, but it apparently prevents the function from executing, so I only know something's up, because in this case the date pickers didn't show up.

It's not really a big deal, but keeping comma's at the end is nicer when working with diffs since it keeps the line from changing, just to add a comma.

Anyway, I was very surprised by this, lesson (hopefully) learned. So... Note to self, don't use that trailing , in JavaScript.

No comments:

Post a Comment