Syntax error on external JS file beyond end of file

Discussion in 'Javascript' started by Josh, Oct 14, 2005.

  1. Josh

    Josh Guest

    Hi All,

    I know this is a novice question that I should be able to solve through
    searching but I have Googled my fingers off and not found anything that
    seems to help.

    I have the following HTML file:
    ---
    <html>
    <head>
    <title>Test</title>
    <script type="text/javascript" src="test.js"></script>
    </head>
    <body>
    Hi There. <a href="javascript:doit()">Click Me</a>
    </body>
    </html>
    ---

    The following js file:
    --
    function doit() {
    alert("I did it");
    }
    --

    Running htm file locally (double click) gives me security warning (XP
    SP 2) but if I then select "allow script to run" everything works fine.

    But when I serve page through IIS (localhost) I get a syntax error line
    4 char 4. Of course there is no line 4 in the js file.

    This HAS to be something simple I am missing but I have tried:
    - with and without language attribute in script tag
    - relative and absolute paths for the js file
    - with and without Mime type for js set in IIS

    Only remaining thing I guess it could be is file permissions but
    everything has execute on it as far as I can see.

    Any help appreciated.

    Thanks,

    Josh
     
    Josh, Oct 14, 2005
    #1
    1. Advertising

  2. Josh

    Lee Guest

    Josh said:
    >
    >Hi All,
    >
    >I know this is a novice question that I should be able to solve through
    >searching but I have Googled my fingers off and not found anything that
    >seems to help.
    >
    >I have the following HTML file:
    >---
    ><html>
    > <head>
    ><title>Test</title>
    ><script type="text/javascript" src="test.js"></script>
    ></head>
    ><body>
    >Hi There. <a href="javascript:doit()">Click Me</a>
    ></body>
    ></html>
    >---
    >
    >The following js file:
    >--
    >function doit() {
    > alert("I did it");
    >}
    >--
    >
    >Running htm file locally (double click) gives me security warning (XP
    >SP 2) but if I then select "allow script to run" everything works fine.
    >
    >But when I serve page through IIS (localhost) I get a syntax error line
    >4 char 4. Of course there is no line 4 in the js file.
    >
    >This HAS to be something simple I am missing but I have tried:
    >- with and without language attribute in script tag
    >- relative and absolute paths for the js file
    >- with and without Mime type for js set in IIS
    >
    >Only remaining thing I guess it could be is file permissions but
    >everything has execute on it as far as I can see.


    If the browser can see line 4 to report an error, it's not a
    permissions problem. The browser downloads the file and then
    compiles and executes it. Source code doesn't need execute
    permissions.

    Try your page in a browser that gives useful error messages
    (eg, Firefox).
     
    Lee, Oct 14, 2005
    #2
    1. Advertising

  3. Josh

    Randy Webb Guest

    Josh said the following on 10/14/2005 4:16 PM:

    > Hi All,
    >
    > I know this is a novice question that I should be able to solve through
    > searching but I have Googled my fingers off and not found anything that
    > seems to help.


    Did you try searching the comp.lang.javascript archives for "getting
    useful error messages" ?

    > I have the following HTML file:
    > ---
    > <html>
    > <head>
    > <title>Test</title>
    > <script type="text/javascript" src="test.js"></script>
    > </head>
    > <body>
    > Hi There. <a href="javascript:doit()">Click Me</a>


    <URL: http://jibbering.com/faq/#FAQ4_24 >

    > </body>
    > </html>
    > ---
    >
    > The following js file:
    > --
    > function doit() {
    > alert("I did it");
    > }
    > --
    >
    > Running htm file locally (double click) gives me security warning (XP
    > SP 2) but if I then select "allow script to run" everything works fine.


    Yes, that is a default XP SP2 setting, but it can be disabled:

    Tools>Internet Options>Advanced>"Allow active content....."

    > But when I serve page through IIS (localhost) I get a syntax error line
    > 4 char 4. Of course there is no line 4 in the js file.


    Error message line numbers are not relative to the js file, they are
    relative to the current windows HTML. And even then that is not always
    true. Error line 0 char 0 is a common one.

    > This HAS to be something simple I am missing but I have tried:
    > - with and without language attribute in script tag
    > - relative and absolute paths for the js file
    > - with and without Mime type for js set in IIS


    Place the script contents into the page itself, test it and then go from
    there.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
     
    Randy Webb, Oct 14, 2005
    #3
  4. Josh

    Josh Guest

    Let me follow up my own post, I guess I wasn't clear enough. I do
    appreciate all the feedback.

    This is a dumbed down example. I tried the same thing with a 563 line
    JS file and got error on line 565. And a 32 line JS file and the error
    was on line 33. So the line number does have something to do with the
    length of the JS file. I dumbed down to the simplest example for this
    post and to verify it was really a problem.

    Secondly, I don't need to run on another browser to see useful error
    messages because there is no *real* langauge error (and yes, it works
    fine when the script is put right into the html file, so do the much
    large JS files I really want to use, but I don't want to clutter the
    HTML file with 563 lines of Javascript).

    It has something to do with the way the file is referenced in the HTML
    file or configuration (hence my question about file permissions) and
    possibly with the use of IIS as a server and IE as a browser. But no
    choice on either of those, IIS will be the server this gets deployed on
    and IE is still the #1 browser out there.

    I can't believe I am the first person to come across this.

    Thanks.
     
    Josh, Oct 15, 2005
    #4
  5. Josh

    Lee Guest

    Josh said:

    >Secondly, I don't need to run on another browser to see useful error
    >messages because there is no *real* langauge error


    You're getting an error message from a browser that is known to give useless
    error messages. Why in the world would you imagine that a browser that gives
    useful messages won't help you, just because the error doesn't have anything to
    do with a "real" language error?
     
    Lee, Oct 16, 2005
    #5
  6. Josh

    Josh Guest

    What can I say, when he is right he is right.

    The problem was that automatic document footer is turned on in IIS and
    it is appending the footer to the JS file. So the cause of this is
    found.

    Thanks for all the help.

    Josh
     
    Josh, Oct 17, 2005
    #6
  7. Josh

    Randy Webb Guest

    Josh said the following on 10/17/2005 10:50 AM:

    > What can I say, when he is right he is right.
    >
    > The problem was that automatic document footer is turned on in IIS and
    > it is appending the footer to the JS file. So the cause of this is
    > found.
    >
    > Thanks for all the help.


    Now, if we can just manage to teach you to quote what you are replying to.

    Please quote what you are replying to.

    If you want to post a followup via groups.google.com, don't use the
    "Reply" link at the bottom of the article. Click on "show options" at
    the top of the article, then click on the "Reply" at the bottom of the
    article headers.


    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
     
    Randy Webb, Oct 18, 2005
    #7
    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. Alex D.
    Replies:
    1
    Views:
    9,627
    Alex D.
    May 20, 2005
  2. solartimba
    Replies:
    2
    Views:
    488
    Mike Wahler
    Nov 3, 2003
  3. Jimmy
    Replies:
    3
    Views:
    356
    J. J. Farrell
    Sep 9, 2011
  4. Jimmy
    Replies:
    13
    Views:
    672
    Peter Nilsson
    Sep 21, 2011
  5. Mark Richards
    Replies:
    3
    Views:
    348
    Tad McClellan
    Nov 18, 2007
Loading...

Share This Page