Connecting Tech Pros Worldwide Forums | Help | Site Map

weird IE bug

lofty00@fastmail.fm
Guest
 
Posts: n/a
#1: Jun 12 '06
I found what looks like a definite bug in IE. If you load the page
below in Firefox, the alert comes up as you would expect. If you run it
in IE6 (with sp2), the alert doesn't come up. commenting out the line
that starts 'div.class' makes it work. This is very weird, as far as I
can see - the code is not run, and it's not generating a syntax error,
but it's still preventing the rest of the program from running. All I
can guess is that the javascript parser has crashed on that line for
some reason without returning an error. It is possible to work round
this using setAttribute, but it's annoying nonetheless.

<html>
<head><title>bug test</title>
<script type="text/javascript">
function notCalled() {
var div=document.createElement("div");
div.class="tabContentPaneDiv";
}

alert("here");
</script>
</head>
<body>
<h1>IE Bug Test</h1>
</body>
</html>


web.dev
Guest
 
Posts: n/a
#2: Jun 12 '06

re: weird IE bug



lofty00@fastmail.fm wrote:[color=blue]
> div.class="tabContentPaneDiv";[/color]

There is no bug. To alter a class for an element, the correct syntax
is:

element.className = "classname";

Changing it to the above will cause your alert to show up.

lofty00@fastmail.fm
Guest
 
Posts: n/a
#3: Jun 12 '06

re: weird IE bug



web.dev wrote:[color=blue]
> lofty00@fastmail.fm wrote:[color=green]
> > div.class="tabContentPaneDiv";[/color]
>
> There is no bug. To alter a class for an element, the correct syntax
> is:
>
> element.className = "classname";
>
> Changing it to the above will cause your alert to show up.[/color]

OK - I had the wrong attribute name for what I was originally trying to
do, but there is still a bug as far as I can see. If you change the
line above it so the function reads:

function notCalled() {
var div={class:0};
div.class="tabContentPaneDiv";
}

The alert doesn't show up. It does in Firefox. This shouldn't happen I
think.

The point is the function is never called, so the only time the
javascript interpreter should look at it is when checking for syntax.
At this point, the interpreter shouldn't be bothered whether the div
variable is a dom node or some other kind of object. But even though
it's not called, assigning to the property name 'class' causes the
program never to be run.

lofty00@fastmail.fm
Guest
 
Posts: n/a
#4: Jun 12 '06

re: weird IE bug



loft...@fastmail.fm wrote:[color=blue]
> web.dev wrote:[color=green]
> > lofty00@fastmail.fm wrote:[color=darkred]
> > > div.class="tabContentPaneDiv";[/color]
> >
> > There is no bug. To alter a class for an element, the correct syntax
> > is:
> >
> > element.className = "classname";
> >
> > Changing it to the above will cause your alert to show up.[/color]
>
> OK - I had the wrong attribute name for what I was originally trying to
> do, but there is still a bug as far as I can see. If you change the
> line above it so the function reads:
>
> function notCalled() {
> var div={class:0};
> div.class="tabContentPaneDiv";
> }
>
> The alert doesn't show up. It does in Firefox. This shouldn't happen I
> think.
>
> The point is the function is never called, so the only time the
> javascript interpreter should look at it is when checking for syntax.
> At this point, the interpreter shouldn't be bothered whether the div
> variable is a dom node or some other kind of object. But even though
> it's not called, assigning to the property name 'class' causes the
> program never to be run.[/color]

I just found out that 'class' is a reserved word in javascript, which
may explain this, though if it is, the interpreter should give a syntax
error, not just stop. This also doesn't explain why it runs OK in
firefox.

Matt Kruse
Guest
 
Posts: n/a
#5: Jun 12 '06

re: weird IE bug


lofty00@fastmail.fm wrote:[color=blue]
> function notCalled() {
> var div={class:0};
> div.class="tabContentPaneDiv";
> }
> The alert doesn't show up. It does in Firefox. This shouldn't happen I
> think.[/color]

I think IE behaves more appropriately.
'class' is a reserved word and can't be used in the manner you are using it.
A decent JS editor will highlight the word and you would know something is
wrong. Further, I *do* get an error in IE. Perhaps your errors are set to
not pop up.

Try this code:

function notCalled() {
var div={'class':0};
div['class']="tabContentPaneDiv";
}
alert ('x');

Works just fine.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com


Tony
Guest
 
Posts: n/a
#6: Jun 13 '06

re: weird IE bug


lofty00@fastmail.fm wrote:[color=blue]
> loft...@fastmail.fm wrote:
>
> I just found out that 'class' is a reserved word in javascript, which
> may explain this, though if it is, the interpreter should give a syntax
> error, not just stop.[/color]

"It would be nice if IE did..."

but it doesn't, so you deal with it. IE pretty much doesn't give errors.

[color=blue]
> This also doesn't explain why it runs OK in
> firefox.[/color]

Firefox ignores it as a keyword (at least in that context) and keeps on
going.


--
"The most convoluted explanation that fits all the available and made-up
facts is the most likely to be believed by conspiracy theorists"
Randy Webb
Guest
 
Posts: n/a
#7: Jun 13 '06

re: weird IE bug


Tony said the following on 6/12/2006 8:58 PM:[color=blue]
> lofty00@fastmail.fm wrote:[color=green]
>> loft...@fastmail.fm wrote:
>>
>> I just found out that 'class' is a reserved word in javascript, which
>> may explain this, though if it is, the interpreter should give a syntax
>> error, not just stop.[/color]
>
> "It would be nice if IE did..."
>
> but it doesn't, so you deal with it. IE pretty much doesn't give errors.[/color]

Yes it does, you just have to learn how to understand them. And
sometimes, IE gives better (more useful) error messages than FF does.
[color=blue]
>[color=green]
>> This also doesn't explain why it runs OK in
>> firefox.[/color]
>
> Firefox ignores it as a keyword (at least in that context) and keeps on
> going.[/color]

Then FF is wrong in that instance. 'class' is a reserved word and FF
should throw an error when it encounters it.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Lasse Reichstein Nielsen
Guest
 
Posts: n/a
#8: Jun 13 '06

re: weird IE bug


Randy Webb <HikksNotAtHome@aol.com> writes:
[color=blue]
> Then FF is wrong in that instance. 'class' is a reserved word and FF
> should throw an error when it encounters it.[/color]

Javascript is allowed to delay failing until the erroneous code is
executed.
I would prefer Firefox to err early (a good principle), but it is allowed
to do as it does (ECMAS262 3rd ed, section 16).
/L
--
Lasse Reichstein Nielsen - lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Tony
Guest
 
Posts: n/a
#9: Jun 14 '06

re: weird IE bug


Randy Webb wrote:[color=blue]
> Tony said the following on 6/12/2006 8:58 PM:[color=green]
>>
>> "It would be nice if IE did..."
>>
>> but it doesn't, so you deal with it. IE pretty much doesn't give errors.[/color]
>
>
> Yes it does, you just have to learn how to understand them. And
> sometimes, IE gives better (more useful) error messages than FF does.[/color]

I haven't found that to be the case - perhaps I just haven't encountered
such a situation.
[color=blue][color=green][color=darkred]
>>> This also doesn't explain why it runs OK in
>>> firefox.[/color]
>>
>> Firefox ignores it as a keyword (at least in that context) and keeps
>> on going.[/color]
>
> Then FF is wrong in that instance. 'class' is a reserved word and FF
> should throw an error when it encounters it.[/color]

Probably - especially as FF claims to support "JavaScript 2.0".


--
"The most convoluted explanation that fits all the available and made-up
facts is the most likely to be believed by conspiracy theorists"
Randy Webb
Guest
 
Posts: n/a
#10: Jun 16 '06

re: weird IE bug


Tony said the following on 6/14/2006 2:09 PM:[color=blue]
> Randy Webb wrote:[color=green]
>> Tony said the following on 6/12/2006 8:58 PM:[color=darkred]
>>>
>>> "It would be nice if IE did..."
>>>
>>> but it doesn't, so you deal with it. IE pretty much doesn't give errors.[/color]
>>
>>
>> Yes it does, you just have to learn how to understand them. And
>> sometimes, IE gives better (more useful) error messages than FF does.[/color]
>
> I haven't found that to be the case - perhaps I just haven't encountered
> such a situation.[/color]

A lot of that depends on what you get used to. The first that comes to
mind is something like this:

<script type="text/javascript" src="ExternalJsFile.js"></script>
<script type="text/javascript">
someFunctionInExternalJsFile()
</script>

Now, assume you have the path wrong to the ExternalJsFile.js, or, you
have a typo in the name of the file.

IE error message:

Line: 2
Character: 1
Error: Invalid Character

FF error message:

Error: someFunctionIn is not defined

Neither exactly tells you what the problem is - that the external file
didn't get loaded. But IE never makes it to the function call. So which
is a better error message?

That is the first that comes to mind because I have seen it so many
times that when I see it I already know what is wrong without looking.

That doesn't mean I think IE always gives better error messages because
it doesn't. But FF doesn't always either. A better error message for the
above problem would be something like "File failed to load" or "File not
found". But both IE and FF's error message was useless.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Tony
Guest
 
Posts: n/a
#11: Jun 16 '06

re: weird IE bug


Randy Webb wrote:[color=blue]
> Tony said the following on 6/14/2006 2:09 PM:
>[color=green]
>> Randy Webb wrote:
>>[color=darkred]
>>> Yes it does, you just have to learn how to understand them. And
>>> sometimes, IE gives better (more useful) error messages than FF does.[/color]
>>
>> I haven't found that to be the case - perhaps I just haven't
>> encountered such a situation.[/color]
>
> A lot of that depends on what you get used to. The first that comes to
> mind is something like this:
>
> <script type="text/javascript" src="ExternalJsFile.js"></script>
> <script type="text/javascript">
> someFunctionInExternalJsFile()
> </script>
>
> Now, assume you have the path wrong to the ExternalJsFile.js, or, you
> have a typo in the name of the file.
>
> IE error message:
>
> Line: 2
> Character: 1
> Error: Invalid Character
>
> FF error message:
>
> Error: someFunctionIn is not defined
>
> Neither exactly tells you what the problem is - that the external file
> didn't get loaded. But IE never makes it to the function call. So which
> is a better error message?
>
> That is the first that comes to mind because I have seen it so many
> times that when I see it I already know what is wrong without looking.[/color]

Hm - I suppose I can see that. To me, the Firefox error is better. But
if the IE one works better for you, I certainly won't argue.
[color=blue]
> That doesn't mean I think IE always gives better error messages because
> it doesn't. But FF doesn't always either. A better error message for the
> above problem would be something like "File failed to load" or "File not
> found". But both IE and FF's error message was useless.[/color]

I'd say I agree on that point.

--
"The most convoluted explanation that fits all the available and made-up
facts is the most likely to be believed by conspiracy theorists"
Randy Webb
Guest
 
Posts: n/a
#12: Jun 16 '06

re: weird IE bug


Tony said the following on 6/16/2006 1:40 PM:[color=blue]
> Randy Webb wrote:[/color]

<snip>
[color=blue][color=green]
>> That doesn't mean I think IE always gives better error messages
>> because it doesn't. But FF doesn't always either. A better error
>> message for the above problem would be something like "File failed to
>> load" or "File not found". But both IE and FF's error message was
>> useless.[/color]
>
> I'd say I agree on that point.[/color]

The error message for that code when run in Opera9 is:

Event thread: BeforeExternalScript
Linked script not loaded

Now *that* is a useful error message :)

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Closed Thread


Similar JavaScript / Ajax / DHTML bytes