user47322
user47322

Reputation:

'Object Expected' Javascript error in IE8 when using prototype.js

function icPageInit()
{
    $("icImgDiv" + icAlternate()).setOpacity(0);
    return true;
}
window.onload = icPageInit;

This piece of Javascript code works fine in Firefox and Chrome, but fails with the error 'Object Expected' in Internet Explorer 8. IE8 says the error occurs on line 3 of the above code.

Does anyone know why this is happening, and/or how to get it working?

Upvotes: 4

Views: 43521

Answers (3)

sanedisk
sanedisk

Reputation: 21

Also check that the script tag's type is "text/javascript". I had this error in IE8, and fixed it by changing the type= part of the script tag from "application/javascript" to "text/javascript".

Upvotes: 2

user47322
user47322

Reputation:

Figured it out.

Turns out Internet Explorer chokes if you use anything other than "javascript" in the language attribute of the script tag.

I was using version numbers appended onto javascript in the language attribute, which was causing IE not to load prototype.js.

Upvotes: 13

PatrikAkerstrand
PatrikAkerstrand

Reputation: 45721

Are you sure that this: $("icImgDiv" + icAlternate()) returns a reference to an element? If so, have you tried using Microsoft Script Debugger / Visual Studio to debug when and where the exception is raised?

Upvotes: 2

Related Questions