Date Script not working on Mozilla

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Sanderson

    #1

    Date Script not working on Mozilla

    I have a script that reads the computer date and writes it to a copyrite
    footer on a web page. The idea is to avoid having to update each page
    manually at the start of a new year. It works fine on Internet Explorer
    but not on Mozilla.

    Here's the script:

    <script type="text/javascript" language="JavaS cript">
    copyright=new Date();
    update=copyrigh t.getYear();
    document.write( "Copyright &copy; Acme Widgets 2000-"+ update + "");
    </script>

    Explorer displays "Copyright © Acme Widgets 2000-2004" but Mozilla displays
    it as "Copyright © Acme Widgets 2000-104"

    Can anyone explain what the problem is or suggest some alternate coding
    that will do what I want?

    Any help will be greatly appreciated.
  • Michael Winter

    #2
    Re: Date Script not working on Mozilla

    On Fri, 10 Dec 2004 22:33:52 GMT, Bob Sanderson
    <sandman@LUVSPA Msandmansoftwar e.com> wrote:

    [snip]
    [color=blue]
    > <script type="text/javascript" language="JavaS cript">[/color]

    Remove the language attribute. It's deprecated and redundant.
    [color=blue]
    > copyright=new Date();
    > update=copyrigh t.getYear();[/color]

    Date.prototype. getYear is supposed to return the year - 1900. So, Mozilla
    is correct and IE isn't following standards. Use getFullYear instead.
    [color=blue]
    > document.write( "Copyright &copy; Acme Widgets 2000-"+ update + "");[/color]

    That empty string at the end is unnecessary. You can remove it.

    [snip]

    Mike

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

    Comment

    • Mick White

      #3
      Re: Date Script not working on Mozilla

      Bob Sanderson wrote:
      [...][color=blue]
      > Here's the script:
      >
      > <script type="text/javascript" language="JavaS cript">
      > copyright=new Date();
      > update=copyrigh t.getYear();
      > document.write( "Copyright &copy; Acme Widgets 2000-"+ update + "");
      > </script>
      >
      > Explorer displays "Copyright © Acme Widgets 2000-2004" but Mozilla displays
      > it as "Copyright © Acme Widgets 2000-104"[/color]


      <script type="text/javascript">
      document.write ("Copyright &copy; Acme Widgets 2000-"+ new
      Date().getFullY ear(););
      </script>

      Mick

      Comment

      • Bob Sanderson

        #4
        Re: Date Script not working on Mozilla

        "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote in
        news:opsitehpwj x13kvk@atlantis :
        [color=blue]
        > On Fri, 10 Dec 2004 22:33:52 GMT, Bob Sanderson
        > <sandman@LUVSPA Msandmansoftwar e.com> wrote:
        >
        > [snip]
        >[color=green]
        >> <script type="text/javascript" language="JavaS cript">[/color]
        >
        > Remove the language attribute. It's deprecated and redundant.
        >[color=green]
        >> copyright=new Date();
        >> update=copyrigh t.getYear();[/color]
        >
        > Date.prototype. getYear is supposed to return the year - 1900. So,
        > Mozilla is correct and IE isn't following standards. Use getFullYear
        > instead.
        >[color=green]
        >> document.write( "Copyright &copy; Acme Widgets 2000-"+ update + "");[/color]
        >
        > That empty string at the end is unnecessary. You can remove it.[/color]

        That was an error. The line should be document.write( "Copyright &copy;
        Acme Widgets 2000 - "+ update + ". All rights reserved.");

        Comment

        • Dr John Stockton

          #5
          Re: Date Script not working on Mozilla

          JRS: In article <Xns95BBB1D6CC0 C5sandmanLUVSPA Msandma@69.28.1 86.158>,
          dated Fri, 10 Dec 2004 22:33:52, seen in news:comp.lang. javascript, Bob
          Sanderson <sandman@LUVSPA Msandmansoftwar e.com> posted :
          [color=blue]
          >I have a script that reads the computer date and writes it to a copyrite
          >footer on a web page. The idea is to avoid having to update each page
          >manually at the start of a new year.[/color]

          That's rather stupid, since a year which is not generated at the same
          time as the rest of the material is generated can have no legal effect;
          indeed, it amounts to an attempt to pass off material as being newer
          than it really is, which could eventually be a preliminary to a false
          action by you for breach of copyright, or to an action against you based
          on deception. It's certainly unprofessional. And your spelling-checker
          is defective.

          If the page is generated by a server-side script, then it may be right
          to claim current copyright; but in that case the script itself should
          insert the year.
          [color=blue]
          > It works fine on Internet Explorer
          >but not on Mozilla.
          >
          >Here's the script:
          >
          ><script type="text/javascript" language="JavaS cript">
          >copyright=ne w Date();
          >update=copyrig ht.getYear();
          >document.write ("Copyright &copy; Acme Widgets 2000-"+ update + "");
          ></script>
          >
          >Explorer displays "Copyright © Acme Widgets 2000-2004" but Mozilla displays
          >it as "Copyright © Acme Widgets 2000-104"
          >
          >Can anyone explain what the problem is or suggest some alternate coding
          >that will do what I want?[/color]

          Method getYear, according to ECMA 262, should return year-1900. AIUI,
          in practice "Method getYear can return any one of these three
          sequences for years:
          97,98,99,00,01 or 97,98,99,2000,2 001 or 97,98,99,100,10 1".

          If you are mortal, then 2000+getYear()% 100 should be reasonably safe
          for you to use. Otherwise getFullYear() if you are prepared to
          ignore those with particularly old browsers. It is always safe to
          determine the correct year from new Date().valueOf( ) . But remember
          that the Gregorian year number is not always the same world-wide.

          Read the newsgroup FAQ, as posted every Wednesday and every Mon/Fri.
          That should be done before posting to a newsgroup; and, if you had read
          ours carefully enough, you would not have needed to ask that question.

          --
          © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
          Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
          PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
          Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.

          Comment

          Working...