Opera 7.54 Javascript Errors

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Pappert

    #1

    Opera 7.54 Javascript Errors

    I've got a linked 'common.js' file that contains one function, on IE
    and Firefox everything works as expected. However, Opera generates the
    following error:



    Unknown context
    Syntax error while loading (line 61)

    -^


    line 61 is the close } of the function?

    Now I'm not sure if this is related to my other problem, but when I
    click the Opera Test link (to create the popup) it generates this
    error:



    Javascript URL thread:
    "javascript:pop upWindow('http://www.mdocs.ca/feedback.htm',' feedback',460,4 15,0,0,'yes','n o','no','n..."
    Error:
    name: ReferenceError
    message: Statement on line 1: Reference to undefined variable: No such
    variable 'popupWindow'
    Backtrace:
    In unknown script
    popupWindow("ht tp://www.mdocs.ca/feedback.htm", "feedback", 460,
    415, 0, 0, "yes", "no", "no", "no");


    It says that it can't reference the variable 'popupWindow' when in
    fact, its a function that is defined in the linked common.js file.
    Any ideas?

    Cheers!
    M.

  • Michael Winter

    #2
    Re: Opera 7.54 Javascript Errors

    On 14 Aug 2004 21:16:37 -0700, Mark Pappert <pappertm@hotma il.com> wrote:
    [color=blue]
    > I've got a linked 'common.js' file that contains one function, on IE
    > and Firefox everything works as expected. However, Opera generates the
    > following error:
    >
    >
    > http://www.mdocs.ca/scripts/common.js
    > Unknown context
    > Syntax error while loading (line 61)
    >
    > -^
    >
    >
    > line 61 is the close } of the function?[/color]

    <!-- mdocs.ca Common Scripts v0.1 | Copyright (c) 2004, Immergis
    Corporation. All Rights Reserved -->

    I'm curious to know why you're using SGML comments in a JavaScript file.
    Use SGML delimiters in HTML and

    // Single line
    /* or
    Multi-line */

    comments in scripts. Removing the final SGML comment, or replacing it with
    an equivalent script comment allows the script to run, but *ALL* of them
    should be replaced.
    [color=blue]
    > Now I'm not sure if this is related to my other problem, but when I
    > click the Opera Test link (to create the popup) it generates this
    > error:[/color]

    If the script doesn't load properly, why would the function load properly?
    Of course, it doesn't help that you have more inappropriate comment types
    within the function, too.

    [snip]

    Now to the rest of the script...

    resizable[ optional; value = yes|(no) ]

    Am I to assume that your notation implies the resizable option defaults to
    "no"? If so, it shouldn't. There is no reason why you should restrict the
    users ability to resize the window. For one, unless your specifying exact
    sizes (which you shouldn't), you can't tell how large the users browser
    text will be and whether that will cause the content to be too big for
    your window. There's another (not so significant) reason that I'll come to
    later.

    At least the scrollbars default to 'yes', however I notice that you
    disable them in the call. Again: don't!

    isIE = new Boolean(false);

    Simply

    isIE = false;

    will to, however

    if (navigator.user Agent.indexOf(" MSIE")!=-1) { isIE = true; }
    if (navigator.user Agent.indexOf(" Opera")!=-1) { isIE = false; }

    is nonsense. You cannot reliably detect the browser in use based upon the
    userAgent string. Most browsers, even IE, can have it set to whatever the
    user wants, and there are plenty of browsers that fake other major browser
    types.

    if (isIE == true) {

    It is simpler to write

    if(isIE) {

    <!-- COMMENT[MP]: Adjust Width/Height to Reflect that IE Measures
    Window Size and not Inner Size -->
    width = width + 6; height = height + 32

    <!-- COMMENT[MP]: Adjust Window Size to Account for for WinXP|SP2;
    If Status is 'NO' -->
    if ((navigator.use rAgent.indexOf( "SV1")!=-1) && (status = 'no'))
    { height = height + 20; }

    More nonsense; both the comment types and the code. Your adjustments are
    based upon the assumption that every Windows system in the world is the
    same as yours. It isn't. The size of the title bar, borders, status bar -
    in fact, virtually every component - varies according the to applied
    theme. The only way you can determine the actual sizes is through a direct
    call to the Win32 API, which you obviously can't do from within a script.

    This is the other reason that I mentioned above regarding sizing. If your
    estimates are completely wrong, and they could be, you'll be creating a
    window too small for the content, with no way to resize or scroll.

    win = window.showMode lessDialog(sURL ,sArguments,sFe atures);

    That's all you should really need to test for. If the browser supports
    showModelessDia log(), it should support everything you've done to
    configure the call. So, change

    if (isIE == true) {

    to

    if(window.showM odelessDialog) {

    to get a more reliable idea of what the browser can do. This is called
    feature testing: check that the properties and methods you want to execute
    are available, and use them if they are. The group FAQ can tell you more.

    winLeft = (screen.availWi dth - width) / 2;
    winTop = (screen.availHe ight - height) /2;

    What if the user has multiple monitors?

    Of course, why you need those contact pages in another window is another
    fine question. They will do just as well presented as normal pages.

    In a world where the number of pop-up blockers, both conservative and
    indescriminate, are growing every day, opening new windows (thought
    annoying enough anyway) is a bad idea.

    Finally, you ought to review the group FAQ regarding JavaScript links.
    They make a site dependent for no good reason, cause various other
    (unrelated) problems, and should be avoided in all but a few cases.

    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail

    Comment

    • Ivo

      #3
      Re: Opera 7.54 Javascript Errors

      "Mark Pappert" wrote[color=blue]
      > I've got a linked 'common.js' file that contains one function, on IE
      > and Firefox everything works as expected. However, Opera generates the
      > following error:
      >
      >
      > http://www.mdocs.ca/scripts/common.js
      > Unknown context
      > Syntax error while loading (line 61)
      >
      > -^
      >
      >
      > line 61 is the close } of the function?[/color]

      Remove the SGML comments from the .js file.
      This is a SGML comment:
      <!-- All Rights Reserved -->

      But a javascript comment looks like this:
      // All Rights Reserved

      or this:
      /* All Rights Reserved */

      After you have cleaned up the file, you may want to run it through the
      javascript lint at http://www.crockford.com/javascript/jslint.html to check
      for other problems.

      [color=blue]
      > Now I'm not sure if this is related to my other problem, but when I
      > click the Opera Test link (to create the popup) it generates this
      > error:
      >
      >
      > http://www.mdocs.ca/alpha_v1d814.htm
      > Javascript URL thread:
      >[/color]
      "javascript:pop upWindow('http://www.mdocs.ca/feedback.htm',' feedback',460,4 1
      5,0,0,'yes','no ','no','n..."[color=blue]
      > Error:
      > name: ReferenceError
      > message: Statement on line 1: Reference to undefined variable: No such
      > variable 'popupWindow'[/color]

      Of course not. Poor Opera hasn't understood a single letter from your .js
      file.
      Also putting javascript in the href of a link is usually not a good idea.
      See the FAQ.
      <URL: http://jibbering.com/faq >


      Comment

      • Dr John Stockton

        #4
        Re: Opera 7.54 Javascript Errors

        JRS: In article <opscrgyacgx13k vk@atlantis>, dated Sun, 15 Aug 2004
        06:41:40, seen in news:comp.lang. javascript, Michael Winter <M.Winter@bl
        ueyonder.co.inv alid> posted :[color=blue]
        >
        >Finally, you ought to review the group FAQ regarding JavaScript links.
        >They make a site dependent for no good reason, cause various other
        >(unrelated) problems, and should be avoided in all but a few cases.[/color]


        Does that mean that <a href="javascrip t:testF()">Test </a> is
        deprecated (testF being a function)?

        --
        © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
        <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
        <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
        <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

        Comment

        • Randy Webb

          #5
          Re: Opera 7.54 Javascript Errors

          Dr John Stockton wrote:[color=blue]
          > JRS: In article <opscrgyacgx13k vk@atlantis>, dated Sun, 15 Aug 2004
          > 06:41:40, seen in news:comp.lang. javascript, Michael Winter <M.Winter@bl
          > ueyonder.co.inv alid> posted :
          >[color=green]
          >>Finally, you ought to review the group FAQ regarding JavaScript links.
          >>They make a site dependent for no good reason, cause various other
          >>(unrelated) problems, and should be avoided in all but a few cases.[/color]
          >
          >
          >
          > Does that mean that <a href="javascrip t:testF()">Test </a> is
          > deprecated (testF being a function)?
          >[/color]

          Its not so much that its deprecated, it creates a javascript dependency
          and is known to cause problems with animated gifs.

          Both issues can be solved by:

          <a href="jsDepende ncy.html" onclick="testF( );return false">Test it</a>

          Where jsDependency.ht ml can be a page that explains the test, maybe even
          provide the function details.

          --
          Randy
          comp.lang.javas cript FAQ - http://jibbering.com/faq

          Comment

          • Lasse Reichstein Nielsen

            #6
            Re: Opera 7.54 Javascript Errors

            Dr John Stockton <spam@merlyn.de mon.co.uk> writes:
            [color=blue]
            > Does that mean that <a href="javascrip t:testF()">Test </a> is
            > deprecated (testF being a function)?[/color]

            If the function returns "undefined" , that is, the URL is only used
            for its side effect, and not as a way to create a replacement for
            the current page, then it should be deprecated. It is misuse of the
            "a" tag, since the URL doesn't refer to another page.

            Instead, one could (and should) use:
            <input type="button" value="Test" onclick="testF( )">
            Buttons are meant to have an effect when pressed. Links are meant
            to lead to another resource. If, for some reason, using a button
            is not acceptable, then at least using
            <a href="youNeedJS .html" onclick="testF( );return false;">Test</a>
            is better, since it gives a default behavior if Javascript is
            disabled (even if that behavior is just to lead to a page that
            explains that Javascript is required)


            If "testF" actually returns the HTML of a new page, then the
            "javascript :" scheme URL is used correctly. However, it still has no
            reasonable behavior if Javascript is not available, and should be
            avoided for that reason alone.


            It's not officially deprecated (since it was never officially defined
            anyway), but I'd recommend against it when used on the internet (where
            ~10% are surfing without Javascript according to some statistics, although
            that number seems to be dropping).

            /L
            --
            Lasse Reichstein Nielsen - lrn@hotpop.com
            DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
            'Faith without judgement merely degrades the spirit divine.'

            Comment

            • Dr John Stockton

              #7
              Re: Opera 7.54 Javascript Errors

              JRS: In article <brhcrkty.fsf@h otpop.com>, dated Mon, 16 Aug 2004
              02:24:41, seen in news:comp.lang. javascript, Lasse Reichstein Nielsen
              <lrn@hotpop.com > posted :[color=blue]
              >Dr John Stockton <spam@merlyn.de mon.co.uk> writes:
              >[color=green]
              >> Does that mean that <a href="javascrip t:testF()">Test </a> is
              >> deprecated (testF being a function)?[/color]
              >
              >If the function returns "undefined" , that is, the URL is only used
              >for its side effect, and not as a way to create a replacement for
              >the current page, then it should be deprecated. It is misuse of the
              >"a" tag, since the URL doesn't refer to another page.[/color]

              It has no return statement, the function being used for side-effect.

              [color=blue]
              >If "testF" actually returns the HTML of a new page, then the
              >"javascript: " scheme URL is used correctly. However, it still has no
              >reasonable behavior if Javascript is not available, and should be
              >avoided for that reason alone.[/color]

              It's reasonable to expect that javascript is available to the reader of
              that page, whether or not it is currently operational, since the
              document in question describes itself, more or less, as a javascript
              FAQ. Not, of course, the JL/RC one.


              Perhaps Martin would be the best person to look into improving that FAQ,
              which also has an ingenious, but unsymmetrical, rounding-to-decimal-
              string routine.

              There's a certain charm in a FAQ which, in referring to presenting a
              lastModified date in the usual local form, chooses Jan 1st for an
              example - no, it's worse than that, it shows the actual live string, and
              the page was edited on Jan 1st. A fresh local copy shows me
              (unconverted)
              document.lastMo dified: 08/16/04 21:40:24


              I tried Tidy on it; and, for comparison, on our FAQ. Early in our sec
              2.3, it objects to the space before http:// ; it likes theirs less.

              --
              © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
              <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
              <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
              <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

              Comment

              Working...