More JavaScript behavior differences between Firefox and IE

In addition to my previous post about JavaScript behavior difference between Firefox and IE, here are two more:

1. If JavaScript attempts to access HTML before IE finished loading it, you might get “Operation aborted” error. Firefox appears to be very flexible on this and will execute such JavaScript without error. To work around this error, delay the access until onDOMReady or window.onload event fired. Here is another blog entry on this topic.

2. You can load the following JavaScript in Firefox if myObjectType constructor exists and works.

a = new myObjectType();

However IE does not like the code if variable a is not declared earlier and will not stop complaining until you add the declaration. Here is one way to do it.

var a;
a = new myObjectType();

This is one difference that I actually prefer IE’s behavior, so I know a bad syntax exists in the code and fix it before it leads to other unintended consequences.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s