Consider the following scenario: file.html contains inline JS code to load remote.js and call a function in remote.js
alert('Before loading remote.js');
document.write('
alert('After loading remote.js');
document.write('
And in remote.js
function remoteFunction() {
alert(‘In remote function’);
}
You would expect the output in this order and Firefox actually honors this order correctly:
- Before loading remote.js
- After loading remote.js
- In remote function
IE on the other hand will give you an error (“Object Expected”) and will call the function prematurely. Meaning that it executes before loading remote.js. This is an unexpected behavior. Fortunately, you can add the attribute defer=”defer”. This will specifically prevent IE from executing and actually produce proper result. Hmm, it’s IE! It has its own style!
Leave a Reply