javascript works in IE, not in firefox

J

Jeff North

On Mon, 26 Nov 2007 16:05:30 -0800 (PST), in comp.lang.javascript
(e-mail address removed)
| Hello,
| I am having an issue with javascript in firefox. On this URL,
| there should be a menu displayed above a dashed line. Works ok in IE6
| & 7 but no menu displays in firefox. Any sugestions?
|
| http://classifiedads.officeresalesolutions.com/TesT.html
|

Line 30: tr not defined.
-- -------------------------------------------------------------
(e-mail address removed) : Remove your pants to reply
-- -------------------------------------------------------------
 
D

Doug Gunnoe

Hello,
I am having an issue with javascript in firefox. On this URL,
there should be a menu displayed above a dashed line. Works ok in IE6
& 7 but no menu displays in firefox. Any sugestions?

http://classifiedads.officeresalesolutions.com/TesT.html

Thanks!

Tim

Hi Tim. I see you are using the "<center>" tag. Try taking that out
and see what happens. I'm pretty sure that tag is no longer valid HTML
and most likely not good in XHTML either.
 
D

Doug Gunnoe

Doug Gunnoe said the following on 11/26/2007 9:44 PM:



Wow. And you think that is causing a JS error of "tr is not defined"?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

No. It would not cause that error. The OP did not post that error and
I did not read your reply right away. I was thinking it could have
been some kind of parsing error causing his image not to show. But
actually you are correct.

"if(LOGGEDIN == null) {
stuff......tr(false);"

And then he calls this several times tr(true) etc. Yet there is no tr
function declared anywhere.

I would appear that IE handles this by continuing to load the page and
Firefox stops.
 
D

Doug Gunnoe

Doug Gunnoe said the following on 11/26/2007 9:44 PM:



Wow. And you think that is causing a JS error of "tr is not defined"?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

I'm off to a brilliant start in the javascript group. :|

Uhm, so I am bored and I took another look.

IE does not show an error until line 55 and it is not the same error.

And the OP is using document.write to print his menu.

here is the relevant part of the script.

if (typeof(loc)=="undefined" || loc==""){

var loc="";

var tt=document.body.innerHTML;
var ml=tt.match(/["']([^'"]*)orsclassnav.js["']/i);

if(ml && ml.length > 1) loc=ml[1];

}
}

document.write("<table border=\"0\" cellspacing=\"0\" cellpadding=
\"0\"><tr>");
tr(false); <--error here in FireFox

So my question, just to satisfy my own curiosity, what is it that
passes for IE here but fails for Firefox?

...You know there is more than one tr(true) on line 30, so, I think
that is enough for me.

Good luck.
 
T

Tim in Phoenix

Randy & Doug,
Thank you for the replies and information. What is the recommended
HTML standard to use since it's clearly not XHTML? The js building
the menus was generated from a program named Xara Webstyle 4 and was a
cut/paste into the js file being used; I'll have to find out why tr is
not defined, but also want to ensure that I'm using the correct HTML
spec.

Thanks again,
Tim
 
R

Richard Cornford

I'm off to a brilliant start in the javascript group. :|

I am not sure anyone ever gets of to "a good start" in this group. If you want to go on better
it would be a good idea to see if you can identify and read the group's FAQ, particularly the
material it contains (and refers to) on posting/quoting conventions.
Uhm, so I am bored and I took another look.

IE does not show an error until line 55 and it is
not the same error.

No there is a good reason for that.
And the OP is using document.write to print his menu.

And Randy is correct in stating that document.wirte does not work at all in XHTML DOMs, but that
is not a factor here as the page is served to Firefox browsers with a text/html content type
header so whatever the mark-up may resemble it is always being interpreted as tag soup HTML.
That is, even on browsers that support XHTML we or working with HTML here, and it is an HTML DOM
that is being scripted. The - document.write - calls will work here as programmed, the insanity
of using mark-up that resembles XHTML here is that in the event that the mark-up ever is
interpreted as XHTML by a browser the scripts on the page will immediately stop working.
here is the relevant part of the script.

if (typeof(loc)=="undefined" || loc==""){

var loc="";

var tt=document.body.innerHTML;
var ml=tt.match(/["']([^'"]*)orsclassnav.js["']/i);

if(ml && ml.length > 1) loc=ml[1];

}
}

document.write("<table border=\"0\" cellspacing=\"0\"
cellpadding= \"0\"><tr>");
tr(false); <--error here in FireFox

So my question, just to satisfy my own curiosity, what
is it that passes for IE here but fails for Firefox?
<snip>

Be careful what you wish for, as you may get it.

Javascript has a formal specification; ECMA 262, which defines the behaviour that is required of
implementations (which are then known as ECMAScript implementations). The specification defines
the syntax for the language, but it also allows for extensions, and for more tolerant
interpretations of the syntax (this means that an ECMAScript implementation must provide
everything specified by ECMA 262 but may provide more, and an implementation may elect to cope
with some ECMA 262 syntax errors as if they were not errors but it is not allowed to treat
anything that is valid by ECMA 262 as an error).

Disregarding most of the code on the page the problem boils down to code like:-

if(something){
tr();
function tr(){
// do something
}
}else{
tr();
function tr(){
// do something else.
}
}

- and in ECMAScript terms that is a syntax error. It should not be expected to work at all, so
it should not be at all surprising if when it does 'work' it does so inconsistently.

What appears above is an apparent attempt to conditionally create a - tr - function by placing
two function declarations in the branches of an - if-else - statement. It is a syntax error
because the two distinct syntax units from which an ECMAScript Program is constructed are
Statements and FunctionDeclarations, and as a result you cannot put a FunctionDeclarations
inside a Statement.

When javascript is executed FunctionDeclarations are acted upon prior to the execution of any
Statements in the pertinent execution context (i.e all declared functions will exist before any
of the code that can use them starts to be executed).

The ECMAScript implementation in IE browsers is JScript(tm) and it is tolerant of the above
syntax error. It ignores the fact that function declarations appear inside a statement and just
treats them as normal function declarations. It creates the corresponding function objects
before any other code is executed. So JScript treats the code above as if it was:-

function tr(){
// do something
}
function tr(){
// do something else.
}
if(something){
tr();
}else{
tr();
}

- and because there are two declarations for the same function two function objects get created
but the second one effectively replaces the first and becomes the one that defines - tr -.

Here executing - tr - is not a problem because the functions have been created before the call
is executed. Though the functions have not been created conditionally so the actual - tr - used
may coincidentally be the wrong one for the IE.

The ECMAScript implementation in Firefox is JavaScript(tm), and it has an extension (an extra
facility) that is a FunctionStatement. A FunctionStatement looks just like a FunctionDeclaration
but being a statement it is allowed to appear inside a BlockStatment. So when JavaScript(tm)
sees what would otherwise appear to be a FunctionDeclaration in a context where only a Statement
would be allowed it interprets that code as a FunctionStatement.

FunctionStatements are evaluated (and the corresponding function objects created) when execution
gets to the statement in the code. So in Firefox the original code gets to the execution of
the - tr - function before it has evaluated the FunctionStatements and so it is trying to
execute the function before the function has been created. Hence the error on Firefox.

Richard.
 
T

Thomas 'PointedEars' Lahn

Doug said:
Hi Tim. I see you are using the "<center>" tag. Try taking that out
and see what happens. I'm pretty sure that tag is no longer valid HTML
and most likely not good in XHTML either.

It is Valid in HTML 3.2, HTML 4.01 Transitional and XHTML 1.0 Transitional.
It is not Valid in HTML 4.01 Strict, XHTML 1.0 Strict, and XHTML 1.1.

RTFS (Read The F*** Specification): http://www.w3.org/TR/


PointedEars
 
T

Tim in Phoenix

I made a change to HTML 4.01 transitional and also changed the js to
call another js depending on whether or not the user is logged in. So
now the page passes validation and also displays the menu in both FF &
IE. The code that originally contained the undefined 'tr' function
has been moved into a separate js file. The error console no longer
shows tr as being undefined, so was it the change from XHTML to HTML
that resolved this, or something due to the nested js call?

Thanks again for the useful information!

Tim
 
T

Tim in Phoenix

I made a change to HTML 4.01 transitional and also changed the js to
call another js depending on whether or not the user is logged in. So
now the page passes validation and also displays the menu in both FF &
IE. The code that originally contained the undefined 'tr' function
has been moved into a separate js file. The error console no longer
shows tr as being undefined, so was it the change from XHTML to HTML
that resolved this, or something due to the nested js call?

Thanks again for the useful information!

Tim
 
T

Thomas 'PointedEars' Lahn

Randy said:
Tim in Phoenix said the following on 11/29/2007 12:09 AM:

Thanks for quoting *something* when you reply next time.

There was _not_ the need to quote anything *here*.

So much for pedanticism.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Randy said:
Tim in Phoenix said the following on 11/29/2007 12:09 AM:

Thanks for quoting *something* when you reply next time.

There was _not_ the need to quote anything *here*.

So much for pedanticism. Pot, kettle, black.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top