Script works when embeded, but not from .js file?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Andy Stevenson

    Script works when embeded, but not from .js file?

    Hi,

    As subject, I have the following JS in my HTML document & it works fine:

    <SCRIPT type="text/JavaScript">
    <!--
    COPYRIGHT = " : Copyright &copy; Diverse Arts., 2003-";
    function writeCopyright( )
    {
    document.write( COPYRIGHT, new Date().getFullY ear(), ". All rights
    reserved.");
    }
    var m = "Page updated " + document.lastMo dified;
    var p = m.length-8;
    document.write( m.substring(p, 0));
    writeCopyright( );
    // End -->
    </SCRIPT>

    when I put this in footer.js & call it with <SCRIPT TYPE="text/javascript"
    SRC="/js/footer.js"></SCRIPT> I get nothing.

    Javascripts not my strong suit, so apologies if I'm missing something
    obvious, but anyone got an idea why this won't work?

    TIA.

    --
    Andy
    "A little pain never hurt anyone!" Sam, aged 11


  • Thomas 'PointedEars' Lahn

    #2
    Re: Script works when embeded, but not from .js file?

    Andy Stevenson wrote:[color=blue]
    > As subject, I have the following JS in my HTML document & it works fine:
    >
    > <SCRIPT type="text/JavaScript">[/color]

    You should lowercase tag names, attribute names and MIME types.
    [color=blue]
    > <!--[/color]

    Remove that, it is obsolete.
    [color=blue]
    > [...]
    > // End -->[/color]

    You should remove that, too.
    [color=blue]
    > </SCRIPT>[/color]

    See above.
    [color=blue]
    > when I put this in footer.js & call it with <SCRIPT TYPE="text/javascript"
    > SRC="/js/footer.js"></SCRIPT> I get nothing.[/color]

    Wrong, you get a script error, but your current environment does not
    show it.
    [color=blue]
    > Javascripts not my strong suit, so apologies if I'm missing something
    > obvious, but anyone got an idea why this won't work?[/color]

    Because HTML is not J(ava)Script. You need to remove any HTML code
    from the .js file (unless it is located within string literals).


    PointedEars

    Comment

    • Dr John Stockton

      #3
      Re: Script works when embeded, but not from .js file?

      JRS: In article <pADNc.506$kT.2 5@newsfe3-gui.ntli.net>, dated Wed, 28
      Jul 2004 01:47:01, seen in news:comp.lang. javascript, Andy Stevenson
      <no@chance.co m> posted :[color=blue]
      >Hi,
      >
      >As subject, I have the following JS in my HTML document & it works fine:
      >
      ><SCRIPT type="text/JavaScript">
      ><!--
      >COPYRIGHT = " : Copyright &copy; Diverse Arts., 2003-";
      >function writeCopyright( )
      >{
      >document.write (COPYRIGHT, new Date().getFullY ear(), ". All rights
      >reserved.");
      >}[/color]

      That should be legally ineffective. Copyright dates from the final
      creative act, not from the date of reading the document. If you cannot
      update the date once every few years to prove you're alive, you do not
      deserve fresh copyright.
      [color=blue]
      >var m = "Page updated " + document.lastMo dified;
      >var p = m.length-8;
      >document.write (m.substring(p, 0));[/color]

      That will, for some combinations of browser and user, display the date
      in a potentially-misleading transatlantic form.

      At least one browser, I am told, does not put the time at the end of the
      string; you will mis-cut.

      Generally, it will not be clear whether the date is user's local or GMT.
      It cannot be author's local, as such.

      An author should be capable of updating the date, in HTML text, when he
      changes the page significantly; it should be left unchanged if, for
      example, minor non-deceptive typos are corrected.

      <URL:http://www.merlyn.demo n.co.uk/js-date3.htm#lM>.

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

      • Andy Stevenson

        #4
        Re: Script works when embeded, but not from .js file?

        [snip][color=blue]
        > That should be legally ineffective. Copyright dates from the final
        > creative act, not from the date of reading the document. If you
        > cannot update the date once every few years to prove you're alive,
        > you do not deserve fresh copyright.[/color]
        [snip][color=blue]
        > That will, for some combinations of browser and user, display the date
        > in a potentially-misleading transatlantic form.
        >
        > At least one browser, I am told, does not put the time at the end of
        > the string; you will mis-cut.
        >
        > Generally, it will not be clear whether the date is user's local or
        > GMT. It cannot be author's local, as such.
        >
        > An author should be capable of updating the date, in HTML text, when
        > he changes the page significantly; it should be left unchanged if, for
        > example, minor non-deceptive typos are corrected.
        >
        > <URL:http://www.merlyn.demo n.co.uk/js-date3.htm#lM>.[/color]

        Fair comments, I'm just playing around with lazy ways to do stuff at the
        moment. I've not investigated the legallities of copyright yet. We're a long
        way from that at the moment :)

        Thank you both for the replies, script now working & I've learnt a few
        things. Much appriciated.
        --
        Andy
        "A little pain never hurt anyone!" Sam, aged 11


        Comment

        Working...