Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    864
    Thanks
    51
    Thanked 6 Times in 5 Posts

    date doesn't work in Firefox

    I have a little script which gives the date - actually the year - and updates the copyright portion of the page each year automatically. But it fails in Firefox.

    I can't quite see why (well, not at all).

    Does anyone know the reason? Here is the external js:

    copywrite=new Date();
    update=copywrite.getYear();

    and in each page at the bottom:

    <p align="center">
    <span style="color: #C0C0C0; font-family: Arial; font-weight: 700; font-size: 10px; font-style:italic">
    Copyright © Donald Duck 2004-<script language="JavaScript">document.write(update);</script>&nbsp;&nbsp;All Rights Reserved</span></p>

    I guess it'll be obvious but I don't get it.

    In IE it renders: Copyright © Donald Duck 2004-2006 All Rights Reserved

    In FF: Copyright © Donald Duck 2004-106 All Rights Reserved

    Thanks,

    Terry

  • #2
    Regular Coder fishluvr's Avatar
    Join Date
    Nov 2005
    Posts
    110
    Thanks
    1
    Thanked 12 Times in 12 Posts
    update=copywrite.getFullYear();

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,641
    Thanks
    0
    Thanked 649 Times in 639 Posts
    getYear() works differently in different browsers because of a Y2K bug. To get consistent results you need to use getFullYear() which is the Y2K corrected version of the method. If you only want the last two digits of the year then use substr() to extract what you want after retrieving the full 4 digit version.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •