Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > "Object Expected" error in IE, but no error in Firefox or Opera

Reply
Thread Tools

"Object Expected" error in IE, but no error in Firefox or Opera

 
 
Steve Chapel
Guest
Posts: n/a
 
      09-21-2006
When I load the page
<https://bugzilla.mozilla.org/attachment.cgi?id=237739> with Internet
Explorer 7 RC 1, I get the error "Object Expected" at line 174. When I
click on the button, I also get the same error on line 186. This same
HTML and JavaScript works perfectly in Firefox and Opera. How can I make
the code work in IE?
 
Reply With Quote
 
 
 
 
Richard Cornford
Guest
Posts: n/a
 
      09-21-2006

Steve Chapel wrote:
> When I load the page
> <https://bugzilla.mozilla.org/attachment.cgi?id=237739> with Internet
> Explorer 7 RC 1, I get the error "Object Expected" at line 174. When I
> click on the button, I also get the same error on line 186. This same
> HTML and JavaScript works perfectly in Firefox and Opera. How can
> I make the code work in IE?


The opening SCRIPT tag uses the TYPE attribute:-

type="application/javascript"

- which is not supported by IE at all. As a result the SCRIPT element's
contents are not processed and all the functions it contains are never
defined. There are the objects that are "expected".

Only changing the value of the TYPE attribute to something IE will
recognise (or removing it entirely) would allow the code to run on IE.

Richard.

 
Reply With Quote
 
 
 
 
Steve Chapel
Guest
Posts: n/a
 
      09-21-2006
Richard Cornford wrote:

> The opening SCRIPT tag uses the TYPE attribute:-
>
> type="application/javascript"
>
> - which is not supported by IE at all. As a result the SCRIPT element's
> contents are not processed and all the functions it contains are never
> defined. There are the objects that are "expected".
>
> Only changing the value of the TYPE attribute to something IE will
> recognise (or removing it entirely) would allow the code to run on IE.


You're right. Changing it to type="text/javascript" works. Thanks!

Is there any IETF standard MIME type that will work across all browsers?
Yes, I *am* a hopeless optimist!
 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      09-21-2006
Steve Chapel wrote:
> Richard Cornford wrote:
>
> > The opening SCRIPT tag uses the TYPE attribute:-
> >
> > type="application/javascript"
> >
> > - which is not supported by IE at all. As a result the SCRIPT element's
> > contents are not processed and all the functions it contains are never
> > defined. There are the objects that are "expected".
> >
> > Only changing the value of the TYPE attribute to something IE will
> > recognise (or removing it entirely) would allow the code to run on IE.

>
> You're right. Changing it to type="text/javascript" works. Thanks!
>
> Is there any IETF standard MIME type that will work across all browsers?
> Yes, I *am* a hopeless optimist!


Yes "text/javascript". Browsers are either too old to attach meaning to
it, and so ignore it defaulting to javascript, or they assume it to
mean javascript.

Richard.

 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      09-21-2006
Steve Chapel wrote:

[snip]

> Is there any IETF standard MIME type that will work across all browsers?
> Yes, I *am* a hopeless optimist!


There wasn't until April this year (quite a delay, I know). The
text/javascript and text/ecmascript media types are now registered in
RFC 4329, but are obsolete. The application top-level media type
equivalents are preferred, but will be unrecognised in most browsers.

The best choice, for quite a while yet, is text/javascript.

Mike
 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      09-21-2006
Steve Chapel wrote:

[snip]

> I thought text/javascript wasn't a registered type, even though lots
> of people used it.


The HTML Recommendation used text/javascript in a script element
example, and that's at least one reason why it became popular. The other
popular type (of Netscape origin, I think) is application/x-javascript,
which some servers use when responding with a script.

> Did they just register it in April 2006 as an obsolete type? Just
> curious.


Yes. It was obsoleted because the text top-level media type is meant to
represent content that can be read without processing. A script is not
meant for that. It is solely for user agent interpretation.

[snip]

Mike
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      09-21-2006


Michael Winter wrote:


> The best choice, for quite a while yet, is text/javascript.


Yes, for scripting HTML documents certainly.

If you script pure SVG documents then text/ecmascript is a better choice
as the SVG specification suggests that and at least one viewer, Apache
Batik (tested here with 1.6), does not want to support text/javascript.

--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      09-21-2006

Steve Chapel wrote:
> I thought text/javascript wasn't a registered type, even though lots of
> people used it.



"type" attribute in <script> is just a round around way of former
"language" attribute. It means that it is not an equivalent of some
MIME / Content-Type.
All modern browsers do recognize type="text/javascript", so use it.
IE also recognizes type="text/Jscript" (watch the case) and as it's the
only one ever existed browser with JScript, you can use it as a
bulletproof way to execute IE-specific code (ignored by everyone else).
These are two and only content types you have to know for the next
decade.

> It looks like text/javascript is the way to go until IE x.x recognizes
> application/javascript and earlier versions of IE are nearly unused.


There is no much hope on it (0.01% or less As I said "type"
attribute is not a name of some MIME, just name by itself. The real
MIME type of say JScript is application/x-javascript, this type is
registered on Windows platforms and used internally for WSH files and
bindings. I don't think that Microsoft will break the compatibility for
millions of users for such small and IMO totally artificial issue.

<script type="text/javascript"> for everyone everywhere

<script type="text/Jscript"> to have it parsed by IE only (if really
needed)

 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      09-21-2006

VK wrote:
[...]
> All modern browsers do recognize type="text/javascript", so use it.
> IE also recognizes type="text/Jscript" (watch the case) and as it's the
> only one ever existed browser with JScript, you can use it as a
> bulletproof way to execute IE-specific code (ignored by everyone else).


Hardly "bulletproof" for everyone - Firefox is certainly picky about
type attributes, but Safari quite happily executes:

<script type="text/Jscript">
alert('hi');
</script>

I have also had issues where the type attribute is missing, though I've
never been able to create a test case to prove it - it wasn't my code,
so maybe I'm wrong about the cause.


--
Rob

 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      09-22-2006
RobG wrote:
> Firefox is certainly picky about
> type attributes, but Safari quite happily executes:
>
> <script type="text/Jscript">
> alert('hi');
> </script>


Oh that Safari...
Is there anything this browser (does)&&(does it properly) ? Most of the
time this expression returns false AFAICT.

But you are right, both Safari and Opera do try to execute text/Jscript
as if they indeed had some JScript engine. At the same time Opera
ignores say "text/foobar". So it does recognize the type attribute, it
is just another case of UA spoofing some wannabes are so badly known
for.

So I take my words back about "text/Jscript" bulletproofness. For a
really extended coverage there is only text/javascript with conditional
compilation (IE). I see the most known way right now as
if(window.ActiveXObject), but I wouldn't count on it on a long run:
from my observations as soon as some "reliable" property check goes
into wide use, the spoofing gang adds a loophole for that in their
engines.

Thanks again for your correction.

> I have also had issues where the type attribute is missing, though I've
> never been able to create a test case to prove it - it wasn't my code,
> so maybe I'm wrong about the cause.


You must be thinking of something like:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">

<script type="text/vbscript">
MsgBox("Hi!")
</script>

<script>
// IE now expects VBScript code by default,
// so you get "Syntax error" on the next line
window.alert('Hi!');
</script>

</head>

<body>

</body>
</html>

That's a rather artificial issue with a developer explicetly trying to
make UA dizzy (a la the "Korean issue" in IE) yet theoretically
possible.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie: This CSS works in IE but not in FireFox, Opera, Netscape Jeff HTML 3 06-23-2006 01:42 PM
Numeric CSS class - Firefox complains but Opera OK john@starmarkassociates.co.uk HTML 1 06-22-2006 07:22 PM
Comparisons of IE, Opera and Firefox on DOM (Javascript/CSS) support(Opera wins) Bob HTML 24 05-21-2006 05:31 PM
Works in IE but not in Opera or Firefox John Dalberg HTML 29 11-03-2004 08:44 PM
Opera 7.53 vs Opera 6.0 ? Hockey Buff Computer Support 3 08-17-2004 08:53 PM



Advertisments