javascript works in IE, not in firefox

Discussion in 'Javascript' started by qwarehouse@gmail.com, Nov 27, 2007.

  1. Guest

    , Nov 27, 2007
    #1
    1. Advertising

  2. Jeff North Guest

    On Mon, 26 Nov 2007 16:05:30 -0800 (PST), in comp.lang.javascript

    <>
    wrote:

    >| 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.
    -- -------------------------------------------------------------
    : Remove your pants to reply
    -- -------------------------------------------------------------
     
    Jeff North, Nov 27, 2007
    #2
    1. Advertising

  3. Doug Gunnoe Guest

    On Nov 26, 6:05 pm, wrote:
    > 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.
     
    Doug Gunnoe, Nov 27, 2007
    #3
  4. Doug Gunnoe Guest

    On Nov 26, 11:17 pm, Randy Webb <> wrote:
    > Doug Gunnoe said the following on 11/26/2007 9:44 PM:
    >
    > > On Nov 26, 6:05 pm, wrote:
    > >> 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.

    >
    > 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.
     
    Doug Gunnoe, Nov 27, 2007
    #4
  5. Doug Gunnoe Guest

    On Nov 26, 11:17 pm, Randy Webb <> wrote:
    > Doug Gunnoe said the following on 11/26/2007 9:44 PM:
    >
    > > On Nov 26, 6:05 pm, wrote:
    > >> 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.

    >
    > 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.
     
    Doug Gunnoe, Nov 27, 2007
    #5
  6. 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


    On Nov 27, 4:55 am, Randy Webb <> wrote:
    > Doug Gunnoe said the following on 11/27/2007 4:48 AM:
    >
    > <snip>
    >
    > > document.write("<table border=\"0\" cellspacing=\"0\" cellpadding=
    > > \"0\"><tr>");
    > > tr(false); <--error here in FireFox

    >
    > Because tr is not defined. It was attempted to be defined by a
    > document.write statement.
    >
    > > So my question, just to satisfy my own curiosity, what is it that
    > > passes for IE here but fails for Firefox?

    >
    > IE has no clue what XHTML is so it renders it as tag-soup HTML and
    > allows the document.write call to succeed. Firefox supports XHTML and
    > there is no document.write allowed in XHTML so FF doesn't create the
    > function. Then you get the error message.
    >
    > --
    > Randy
    > Chance Favors The Prepared Mind
    > comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
    > Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/
     
    Tim in Phoenix, Nov 27, 2007
    #6
  7. Doug Gunnoe wrote:
    > On Nov 26, 11:17 pm, Randy Webb wrote:
    >> Doug Gunnoe said the following on 11/26/2007 9:44 PM:
    >>> On Nov 26, 6:05 pm, wrote:
    >>>> 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

    <snip>
    >> comp.lang.javascript FAQ -http://jibbering.com/faq/index.html

    <snip>
    > 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.
     
    Richard Cornford, Nov 27, 2007
    #7
  8. Doug Gunnoe wrote:
    > 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
     
    Thomas 'PointedEars' Lahn, Nov 27, 2007
    #8
  9. Tim in Phoenix wrote:
    > [...] What is the recommended HTML standard to use since it's clearly not
    > XHTML? [...]


    Read my sig.


    PointedEars
    --
    realism: HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness: XHTML 1.1 as application/xhtml+xml
    -- Bjoern Hoehrmann
     
    Thomas 'PointedEars' Lahn, Nov 27, 2007
    #9
  10. 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
     
    Tim in Phoenix, Nov 29, 2007
    #10
  11. 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
     
    Tim in Phoenix, Nov 29, 2007
    #11
  12. Randy Webb wrote:
    > Tim in Phoenix said the following on 11/29/2007 12:09 AM:
    >> Thanks again for the useful information!

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


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

    So much for pedanticism.


    PointedEars
    --
    "Use any version of Microsoft Frontpage to create your site. (This won't
    prevent people from viewing your source, but no one will want to steal it.)"
    -- from <http://www.vortex-webdesign.com/help/hidesource.htm>
     
    Thomas 'PointedEars' Lahn, Nov 29, 2007
    #12
  13. Randy Webb wrote:
    > Tim in Phoenix said the following on 11/29/2007 12:09 AM:
    >> Thanks again for the useful information!

    >
    > 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
    --
    "Use any version of Microsoft Frontpage to create your site. (This won't
    prevent people from viewing your source, but no one will want to steal it.)"
    -- from <http://www.vortex-webdesign.com/help/hidesource.htm>
     
    Thomas 'PointedEars' Lahn, Nov 29, 2007
    #13
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. gizoto316
    Replies:
    2
    Views:
    85
    gizoto316
    Oct 28, 2005
  2. Replies:
    4
    Views:
    266
    Randy Webb
    Feb 18, 2006
  3. goga
    Replies:
    4
    Views:
    146
  4. Replies:
    2
    Views:
    102
    atetlaw
    Jun 22, 2006
  5. SJ Carter
    Replies:
    8
    Views:
    97
    GTalbot
    May 15, 2008
Loading...

Share This Page