Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-27-2006, 05:42 PM   PM User | #1
tpeck
Regular Coder

 
tpeck's Avatar
 
Join Date: Oct 2002
Location: Sydney, Australia
Posts: 771
Thanks: 40
Thanked 5 Times in 4 Posts
tpeck is on a distinguished road
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
tpeck is offline   Reply With Quote
Old 07-27-2006, 05:56 PM   PM User | #2
fishluvr
Regular Coder

 
fishluvr's Avatar
 
Join Date: Nov 2005
Posts: 110
Thanks: 1
Thanked 12 Times in 12 Posts
fishluvr is on a distinguished road
update=copywrite.getFullYear();
fishluvr is offline   Reply With Quote
Old 07-27-2006, 09:06 PM   PM User | #3
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,465
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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/
felgall is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:38 AM.


Advertisement
Log in to turn off these ads.