SRC= and missing .JS file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Gorodyansky

    SRC= and missing .JS file

    Hi,

    Could not find the answer neither in FAQs not on the Web...

    On many javaScript 'tips' sites they say that do warn the user
    regarding missing .JS file one should do the following:
    <html>
    <head>
    ....
    <script src="ABC.js" ...>
    alert("Error! Included JS file not found ...");
    </script>
    </head>
    ....

    But it does NOT work neither in my IE 6 nor in my Mozilla 1.6 -
    no alert when the .JS file does not exist.

    A description of HTML 4's SCRIPT element for client-side scripts.


    says,
    "When the SRC attribute is used, the embedded script is ignored."
    which does not touch the case when .JS not found
    (or does it? Ignored _always_?)

    So how to tell the user that .JS to be included was not found?

    --
    Regards,
    Paul
    http://KBD.da.ru - was possible to develop only because
    of the great article at

  • Dennis M. Marks

    #2
    Re: SRC= and missing .JS file

    In article <36b165a.040409 1454.5fb10364@p osting.google.c om>, Paul
    Gorodyansky <paulgor@compus erve.com> wrote:
    [color=blue]
    > Hi,
    >
    > Could not find the answer neither in FAQs not on the Web...
    >
    > On many javaScript 'tips' sites they say that do warn the user
    > regarding missing .JS file one should do the following:
    > <html>
    > <head>
    > ...
    > <script src="ABC.js" ...>
    > alert("Error! Included JS file not found ...");
    > </script>
    > </head>
    > ...
    >
    > But it does NOT work neither in my IE 6 nor in my Mozilla 1.6 -
    > no alert when the .JS file does not exist.
    >
    > http://www.htmlhelp.com/reference/ht...al/script.html
    >
    > says,
    > "When the SRC attribute is used, the embedded script is ignored."
    > which does not touch the case when .JS not found
    > (or does it? Ignored _always_?)
    >
    > So how to tell the user that .JS to be included was not found?[/color]

    I've been experimenting with the following and it seems to work. In the
    ..js file put the following statement at the top.
    var script111loaded = "true";

    Now in the HTML put
    <script type="text/javascript">
    if (!script111load ed) {alert("script 111 not loaded")};
    </script>

    --
    Dennis M. Marks

    Replace domain.invalid with dcsi.net


    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    -----== Over 100,000 Newsgroups - 19 Different Servers! =-----

    Comment

    • Paul Gorodyansky

      #3
      Re: SRC= and missing .JS file

      Hi,

      Dennis M. Marks wrote:[color=blue][color=green]
      >>...
      >>So how to tell the user that .JS to be included was not found?[/color]
      >
      >
      > I've been experimenting with the following and it seems to work. In the
      > .js file put the following statement at the top.
      > var script111loaded = "true";
      >
      > Now in the HTML put
      > <script type="text/javascript">
      > if (!script111load ed) {alert("script 111 not loaded")};
      > </script>
      >[/color]

      Thanks, it works (though, I had to declare that variable
      at the top of my _html_ text,too - otherwise _if_ did not
      work - just has "undefined" error in JS Console, at least
      in Mozilla 1.6).

      --
      Regards,
      Paul

      Comment

      • Dennis M. Marks

        #4
        Re: SRC= and missing .JS file

        In article <c57jqf$2qlumk$ 1@ID-25072.news.uni-berlin.de>, Paul
        Gorodyansky <paulgor@compus erve.com> wrote:
        [color=blue]
        > Hi,
        >
        > Dennis M. Marks wrote:[color=green][color=darkred]
        > >>...
        > >>So how to tell the user that .JS to be included was not found?[/color]
        > >
        > >
        > > I've been experimenting with the following and it seems to work. In the
        > > .js file put the following statement at the top.
        > > var script111loaded = "true";
        > >
        > > Now in the HTML put
        > > <script type="text/javascript">
        > > if (!script111load ed) {alert("script 111 not loaded")};
        > > </script>
        > >[/color]
        >
        > Thanks, it works (though, I had to declare that variable
        > at the top of my _html_ text,too - otherwise _if_ did not
        > work - just has "undefined" error in JS Console, at least
        > in Mozilla 1.6).[/color]

        I tested it in IE. I should have followed through with Netscape.

        Why doesn't a test like "if (document.getEl ementById) {xxx}" give an
        undefined error in some browsers, or does it?

        --
        Dennis M. Marks

        Replace domain.invalid with dcsi.net


        -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
        http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
        -----== Over 100,000 Newsgroups - 19 Different Servers! =-----

        Comment

        • Dr John Stockton

          #5
          SRC= and missing .JS file

          JRS: In article <36b165a.040409 1454.5fb10364@p osting.google.c om>, seen
          in news:comp.lang. javascript, Paul Gorodyansky <paulgor@compus erve.com>
          posted at Fri, 9 Apr 2004 15:54:16 :
          [color=blue]
          >Could not find the answer neither in FAQs not on the Web...[/color]

          <URL:http://www.merlyn.demo n.co.uk/js-nclds.htm> now answers that.
          [color=blue]
          >So how to tell the user that .JS to be included was not found?[/color]

          I test for the existence of a variable declared in it.

          I don't know about putting material here --------+
          V
          <script type="text/javascript" src="include1.j s"> </script>

          --
          © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
          <URL:http://jibbering.com/faq/> Jim Ley's FAQ for 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

          • Dr John Stockton

            #6
            SRC= and missing .JS file

            JRS: In article <09042004173654 5389%denmarks@d omain.invalid>, seen in
            news:comp.lang. javascript, Dennis M. Marks <denmarks@domai n.invalid>
            posted at Fri, 9 Apr 2004 17:36:54 :[color=blue]
            >
            >I've been experimenting with the following and it seems to work. In the
            >.js file put the following statement at the top.
            >var script111loaded = "true";
            >
            >Now in the HTML put
            ><script type="text/javascript">
            >if (!script111load ed) {alert("script 111 not loaded")};
            ></script>[/color]


            Why did you choose to assign a string to script111loaded ?
            <rhetorical> How about "false", "banana", or just 1 ?

            --
            © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
            <URL:http://jibbering.com/faq/> Jim Ley's FAQ for 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

            • Yann-Erwan Perio

              #7
              Re: SRC= and missing .JS file

              Dr John Stockton wrote:
              [color=blue][color=green]
              >>if (!script111load ed) {alert("script 111 not loaded")};[/color][/color]

              if(!this.script 111loaded) //...
              [color=blue]
              > Why did you choose to assign a string to script111loaded ?
              > <rhetorical> How about "false", "banana", or just 1 ?[/color]

              Well, any non-empty string would technically type-convert to true,
              though I question the semantic value of "banana" for maintenance
              purposes... :-)

              As you suggest, using a boolean instead of a string would definitely be
              a good idea!

              Comment

              • Dennis M. Marks

                #8
                Re: SRC= and missing .JS file

                In article <waLQqEA+BDeAFw dd@merlyn.demon .co.uk>, Dr John Stockton
                <spam@merlyn.de mon.co.uk> wrote:
                [color=blue]
                > JRS: In article <09042004173654 5389%denmarks@d omain.invalid>, seen in
                > news:comp.lang. javascript, Dennis M. Marks <denmarks@domai n.invalid>
                > posted at Fri, 9 Apr 2004 17:36:54 :[color=green]
                > >
                > >I've been experimenting with the following and it seems to work. In the
                > >.js file put the following statement at the top.
                > >var script111loaded = "true";
                > >
                > >Now in the HTML put
                > ><script type="text/javascript">
                > >if (!script111load ed) {alert("script 111 not loaded")};
                > ></script>[/color]
                >
                >
                > Why did you choose to assign a string to script111loaded ?
                > <rhetorical> How about "false", "banana", or just 1 ?[/color]

                True should not have had quotes around it. That was ANOTHER mistake I
                made.

                I don't understand your RHETORICAL response unless it is the quotes.
                Any value would be ok but true is simpler for the IF.

                --
                Dennis M. Marks

                Replace domain.invalid with dcsi.net


                -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
                http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
                -----== Over 100,000 Newsgroups - 19 Different Servers! =-----

                Comment

                • Richard Cornford

                  #9
                  Re: SRC= and missing .JS file

                  Dr John Stockton wrote:[color=blue]
                  > Paul Gorodyansky wrote:[color=green]
                  >>So how to tell the user that .JS to be included was not found?[/color][/color]

                  I can understand why a script may care that a file on which it is
                  dependent has not loaded, but I don't see much point in telling the user
                  in most cases as there is not going to be a great deal that they can do
                  about it (assuming that they understand the role of a JS file in the
                  first place).
                  [color=blue]
                  > I test for the existence of a variable declared in it.
                  >
                  > I don't know about putting material here --------+
                  > V
                  > <script type="text/javascript" src="include1.j s"> </script>[/color]

                  One of the problems with this is how the server reacts to its inability
                  to find the file. A suitable HTTP error response should tell the browser
                  that something is up, but many servers are configured to send custom
                  HTML pages that announce the error to the user but might still give the
                  browser the impression that the resource that was requested has been
                  returned. And an HTML file sent in the pace of a JS file will produce a
                  syntax error, but not necessarily result in the fall-back to using the
                  contents of the script element.

                  Richard.


                  Comment

                  • Paul Gorodyansky

                    #10
                    Re: SRC= and missing .JS file

                    Hello!

                    Richard Cornford wrote:
                    [color=blue]
                    > One of the problems with this is how the server reacts to its inability
                    > to find the file. A suitable HTTP error response should tell the browser
                    > that something is up, but many servers are configured to send custom
                    > HTML pages that announce the error to the user but might still give the
                    > browser the impression that the resource that was requested has been
                    > returned. And an HTML file sent in the pace of a JS file will produce a
                    > syntax error, but not necessarily result in the fall-back to using the
                    > contents of the script element.
                    >
                    > Richard.
                    >[/color]

                    it was exactly my reason to post the question here - with
                    my ISP - CompuServe - *nothing* happens - page loads,... -
                    no error of any kind, so a user is just
                    confused why the expected functionality failing - _I_
                    need to explain the user why :)

                    BTW, obviously I used a _Boolean_ variable after getting
                    a response here :)

                    --
                    Regards,
                    Paul

                    Comment

                    • Michael Winter

                      #11
                      Re: SRC= and missing .JS file

                      On Sat, 10 Apr 2004 08:10:47 -0700, Dennis M. Marks
                      <denmarks@domai n.invalid> wrote:

                      [snip]
                      [color=blue]
                      > Why doesn't a test like "if (document.getEl ementById) {xxx}" give an
                      > undefined error in some browsers, or does it?[/color]

                      In Opera, Mozilla and IE, it does. It probably does in every browser.

                      If the OP wants to avoid getting "undefined" errors, you could do

                      if( 'undefined' == typeof scriptXXXloaded ) {
                      // script XXX is not loaded
                      }

                      and declare scriptXXXloaded somewhere in the script

                      var scriptXXXloaded = true;

                      This will avoid the need to declare the variable in the containing HTML
                      file. The value of the variable itself is irrelevant, just so long as it's
                      not undefined.

                      Mike

                      --
                      Michael Winter
                      M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

                      Comment

                      • Richard Cornford

                        #12
                        Re: SRC= and missing .JS file

                        Michael Winter wrote:[color=blue]
                        > On Sat, 10 Apr 2004 08:10:47 -0700, Dennis M. Marks
                        > <denmarks@domai n.invalid> wrote:
                        >
                        > [snip]
                        >[color=green]
                        >> Why doesn't a test like "if (document.getEl ementById) {xxx}" give an
                        >> undefined error in some browsers, or does it?[/color]
                        >
                        > In Opera, Mozilla and IE, it does. It probably does in every browser.[/color]
                        <snip>

                        "if (document.getEl ementById) {xxx}" - will only produce an undefined
                        error if - document - is undefined (and a different error if null).
                        Reading a non-existent property form an object returns an undefined
                        value, which happily type-converts to boolean false for the expression
                        of the - if - statement (no errors result).

                        The OP's problem with - if(!script111lo aded) { ... }; - is that the
                        scope chain resolution of the identifier for an undeclared (and
                        unassigned) global variable has a null base object on the returned
                        Reference, and the subsequent use of that Reference with the internal -
                        GetValue - function is required to throw an exception when the base
                        object is null.

                        The typeof operator avoids the problem as it has special handling when a
                        Reference has a null base object, but a property accessor, where the
                        identifiers before the property name refer to existing objects, will
                        never return a Reference with a null base object (so it will never throw
                        an exception when used with - GetValue).

                        Richard.


                        Comment

                        • Michael Winter

                          #13
                          Re: SRC= and missing .JS file

                          On Thu, 15 Apr 2004 17:54:51 +0100, Richard Cornford
                          <Richard@litote s.demon.co.uk> wrote:
                          [color=blue]
                          > Michael Winter wrote:[color=green]
                          >> On Sat, 10 Apr 2004 08:10:47 -0700, Dennis M. Marks
                          >> <denmarks@domai n.invalid> wrote:
                          >>
                          >> [snip]
                          >>[color=darkred]
                          >>> Why doesn't a test like "if (document.getEl ementById) {xxx}" give an
                          >>> undefined error in some browsers, or does it?[/color]
                          >>
                          >> In Opera, Mozilla and IE, it does. It probably does in every browser.[/color]
                          >
                          > "if (document.getEl ementById) {xxx}" - will only produce an undefined
                          > error if - document - is undefined (and a different error if null).
                          > Reading a non-existent property form an object returns an undefined
                          > value, which happily type-converts to boolean false for the expression
                          > of the - if - statement (no errors result).[/color]

                          [snip]

                          The problem isn't with the conditional expression, it is with xxx itself.
                          I would guess that as xxx hasn't been previously defined, and isn't part
                          of an assignment (where the variable would become global), the interpreter
                          is trying to evaluate something that obviously doesn't exist, hence the
                          undefined error.

                          Mike

                          --
                          Michael Winter
                          M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

                          Comment

                          • Richard Cornford

                            #14
                            Re: SRC= and missing .JS file

                            Michael Winter wrote:[color=blue]
                            > Richard Cornford wrote:[color=green]
                            >> Michael Winter wrote:[color=darkred]
                            >>> Dennis M. Marks wrote:
                            >>>> Why doesn't a test like "if (document.getEl ementById) {xxx}" give
                            >>>> an undefined error in some browsers, or does it?
                            >>>
                            >>> In Opera, Mozilla and IE, it does. It probably does in every
                            >>> browser.[/color][/color][/color]
                            <snip>[color=blue]
                            > The problem isn't with the conditional expression, it is with xxx
                            > itself. I would guess that as xxx hasn't been previously defined, and
                            > isn't part of an assignment (where the variable would become global),
                            > the interpreter is trying to evaluate something that obviously
                            > doesn't exist, hence the undefined error.[/color]

                            Ah, you are being unusually pedantic. I took the - xxx - as standing in
                            for some unspecified block of code to be executed if -
                            document.getEle mentById - type-converted to true. I usually use - ... -
                            in that context, which will also predictably error if actually executed.

                            Richard.


                            Comment

                            Working...