Javascript: Thoughts on Problems With Internet Explorer

I have been writing a large frontend piece to a Magento module that I’ve been working on for the past couple of months. I am on a Mac, and mainly use Firefox, Safari, and Chrome. I thought I was done with the first release, that is, until I tested it in Internet Explorer.

I ran into a number of problems. Some of them are totally legit IE issues, such as the problem I encountered with setting the innerHTML of a select element. IE cannot do that properly. As far as I can tell, IE has had this issue ever since IE 5. You’d think that they’d have that fixed by now…

There are other problems that I ran into though that turned out to be just badly written javascript on my part. For instance, I had a json string that was something like:

var foobar = {"foo":{"1":5,"2":10,"3":15,},"bar":"blah"}

As you can see, there is a comma after the 15 that is unnecessary. All the browsers except for IE7 worked just fine. IE7 failed to work and errored out.

That leaves me asking this question: Does IE7 suck because of that? Or is IE7 just enforcing proper code and FF, Saf, Chrome are just being lenient with bad code? I almost want to applaud IE7 for being strict enough to force me to make my code right, which is odd because of how much I can’t stand IE.

What do you think? Is it a good thing that Firefox, Safari, and Chrome are all quite forgiving with poorly written javascript?

This entry was posted in Javascript, Magento. Bookmark the permalink.

2 Responses to Javascript: Thoughts on Problems With Internet Explorer

  1. I think you’re right in a sense… This is like “use strict;” in Perl. It’s better to see every error while you’re developing so that you can correct them.

  2. Hi, my name is Jonathan Hodges and I am a developer at Classy Llama. We do Magento development here in Springfield, MO. As I was reading your blog, I had a couple of thoughts and questions.

    Why don’t you use the Zend_Json object that comes with Magento to build your JSON?

    I normally would agree that having IE7 force you to write proper code is a good thing, but I tend not agree in this case. The main reason for my opinion is because of how PHP works. PHP allows you to leave the comma after the element. The logic behind this is sound since if you add elements or reorder them, having the comma at the end prevents errors caused by missing commas and from having extra commas.

    Interestingly, we have found that IE is so bad that it should be done at the end since it has so many non-compliant “features” that it has to be “hacked” to get it working properly.