Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Problem with document.lastModified in Mozilla

Reply
Thread Tools

Problem with document.lastModified in Mozilla

 
 
Bart
Guest
Posts: n/a
 
      02-01-2004
Hallo,

I'm have a problem with the following script:


function wr(s)
{
//Just got tired of writing document.write,
//so I created a shorthand version
document.write(s);
}


function lm()
{
//I know this can be shorter but the original script
//tried to format the outputstring, wichh did not
//work in Mozilla, so I commented a lot out
//and this is what's left of it...
var s = document.lastModified;
return s;
}

function lmstring()
{
var s = "This page was last modified at: ";
s += lm();
s += ".";
return s;
}


<html>

...

<script type="text/JavaScript">
<!--
wr(lmstring());
// -->
</script>

....
</html>


This _should_ return the date and time the document was last modified
(saved), however in Mozilla (1.4; Windows ME) it will return the
actual current date and time (as if I'd used "new Date()").
In IE (5.50) it behaves as I expect.

What am I doing wrong (or is it a Mozilla bug ???).

(The script is in an external .js file, if that should make any
difference)
--
Bart Broersma
http://www.velocityreviews.com/forums/(E-Mail Removed)
(ff _ANTISPAM_ wegpoetsen uit dit adres natuurlijk)
 
Reply With Quote
 
 
 
 
Dr John Stockton
Guest
Posts: n/a
 
      02-02-2004
JRS: In article <(E-Mail Removed)>, seen in
news:comp.lang.javascript, Bart <(E-Mail Removed)>
posted at Sun, 1 Feb 2004 18:30:26 :-
>
>This _should_ return the date and time the document was last modified
>(saved), however in Mozilla (1.4; Windows ME) it will return the
>actual current date and time (as if I'd used "new Date()").
>In IE (5.50) it behaves as I expect.
>
>What am I doing wrong (or is it a Mozilla bug ???).


For testing, and even more so for getting advice, throw all that code
away. It wastes our time.

document.write('"', document.lastModified, '"')

can be understood immediately, and shows exactly what the string
contains.

By reading the FAQ, you could have found
<URL:http://www.merlyn.demon.co.uk/js-date3.htm#lM>, q.v.


You do not say whether you are accessing the file as a file on your
local disc, as a Web page but from a server on your computer, or as a
Web page from a remote server.



The HTTP header line Last-Modified is well-specified; and I suspect
that, where implemented, it is correctly implemented.

But the javascript document.lastModified string appears to be totally
unspecified, or differently specified in different DOMs. If it is to be
correctly interpreted by all browsers, world-wide, it must be carefully
treated.

The reliable, sensible, economical easy approach is to write the date,
in an international standard form, in HTML on the page, and to update it
when you edit the page significantly. Like I do.


Consider

if (new Date() - (D = new Date(document.lastModified)) > 3e4)
LMdisplay(document.lastModified)

Remember that the string may be GMT.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
Reply With Quote
 
 
 
 
@SM
Guest
Posts: n/a
 
      02-02-2004


Bart a ecrit :
>
> Hallo,
>
> I'm have a problem with the following script:


function wr() { document.write(lmstring()); }


> function wr(s)
> {
> //Just got tired of writing document.write,
> //so I created a shorthand version
> document.write(s);
> }
>
> function lm()
> {
> //I know this can be shorter but the original script
> //tried to format the outputstring, wichh did not
> //work in Mozilla, so I commented a lot out
> //and this is what's left of it...
> var s = document.lastModified;
> return s;
> }
>
> function lmstring()
> {
> var s = "This page was last modified at: ";
> s += lm();
> s += ".";
> return s;
> }
>
> <html>
>
> ..
>
> <script type="text/JavaScript">
> <!--
> wr(lmstring());
> // -->
> </script>
>
> ...
> </html>
>
> This _should_ return the date and time the document was last modified
> (saved), however in Mozilla (1.4; Windows ME) it will return the
> actual current date and time (as if I'd used "new Date()").
> In IE (5.50) it behaves as I expect.
>
> What am I doing wrong (or is it a Mozilla bug ???).
>
> (The script is in an external .js file, if that should make any
> difference)
> --
> Bart Broersma
> (E-Mail Removed)
> (ff _ANTISPAM_ wegpoetsen uit dit adres natuurlijk)


--
******** (enlever/remove [OTER_MOI] du/from reply url) *******
Stéphane MORIAUX : (E-Mail Removed)
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephane.moriaux/internet/
************************************************** ************
 
Reply With Quote
 
Bart
Guest
Posts: n/a
 
      02-02-2004
On Mon, 02 Feb 2004 17:34:38 +0100 "@SM" wrote:
<(E-Mail Removed)>:


>function wr() { document.write(lmstring()); }

Actually I use the wr() function in all my pages instead of
document.write, so this won't solve anything for me.
>
>


I think you misunderstood my question.
As fa as I can trace, document.lastModified does not return the date
the document was last modified, but the actual current date & time...

Bart
--
Bart Broersma
(E-Mail Removed)
(ff _ANTISPAM_ wegpoetsen uit dit adres natuurlijk)
 
Reply With Quote
 
Bart
Guest
Posts: n/a
 
      02-02-2004
Op Sun, 01 Feb 2004 18:30:26 +0100 schreef Bart
<(E-Mail Removed)>:

Just tested this (Mozilla 1.4 on Windows ME)

<script type="text/JavaScript">
<!--
document.write(document.lastModified);
// -->
</script>

This will return the actual time and date of my computer clock, _NOT_,
as one should ecxpect, the date & time the document was last modified.

(saved the HTML opened in browser: gave me "february 02, 18:36";
then changed computer clock to december 2nd 2004, reloaded the page
and it gave me "december 02, 2004 18:36" ....)

Netscape 6.0 behaves correctly on the same script...

Can anyone reproduce this ????

Bart
--
Bart Broersma
(E-Mail Removed)
(ff _ANTISPAM_ wegpoetsen uit dit adres natuurlijk)
 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      02-02-2004
"Bart" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
<snip>
>This will return the actual time and date of my computer
>clock, _NOT_, as one should ecxpect, the date & time the
>document was last modified.

<snip>
> Can anyone reproduce this ????


The browser gets its last modified date from the HTTP headers sent with
the HTML when it is downloaded, and only if the server sends that
information. When testing from the file system there are no HTTP
headers, IE may know how to get the information from the (Microsoft) OS;
Mozilla may not (or care to try).

If you want to see if the problem is reproducible you will have to go
into more details on the context. Perhaps a URL to a test file on a
server somewhere.

Richard.


 
Reply With Quote
 
@SM
Guest
Posts: n/a
 
      02-02-2004
Bart a ecrit :
>
> On Mon, 02 Feb 2004 17:34:38 +0100 "@SM" wrote:
> <(E-Mail Removed)>:
>
> As fa as I can trace, document.lastModified does not return the date
> the document was last modified, but the actual current date & time...


If document is not on a server your experencies are of no interest.

On My Mac IE and NC doesn't give same date/hour.

Of course, I didn't try playing with the computer clock !
Some secondes or minutes of waiting is enough to see it is realy
a last time modified, even if the time is false ...

--
******** (enlever/remove [OTER_MOI] du/from reply url) *******
Stéphane MORIAUX : (E-Mail Removed)
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephane.moriaux/internet/
************************************************** ************
 
Reply With Quote
 
Bart
Guest
Posts: n/a
 
      02-03-2004
Op Mon, 2 Feb 2004 18:37:06 -0000 schreef "Richard Cornford"
<(E-Mail Removed)>:

>"Bart" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed).. .
><snip>
>>This will return the actual time and date of my computer
>>clock, _NOT_, as one should ecxpect, the date & time the
>>document was last modified.

><snip>
>> Can anyone reproduce this ????

>
>The browser gets its last modified date from the HTTP headers sent with
>the HTML when it is downloaded, and only if the server sends that
>information. When testing from the file system there are no HTTP
>headers, IE may know how to get the information from the (Microsoft) OS;
>Mozilla may not (or care to try).
>
>If you want to see if the problem is reproducible you will have to go
>into more details on the context. Perhaps a URL to a test file on a
>server somewhere.
>
>Richard.
>


The behaviour is the same on a server (my homepage) or on my local
computer.
I recently tested the same page in Mozilla 1.2.1 and it behaved
normally. (I seem to remeber that Mozilla 1.3 also behaved as I
expected, since I tested all my pages under Mozilla 1.3, before
upgrading to 1.4).

This seems odd...

Thanx anyway !

Bart

--
Bart Broersma
(E-Mail Removed)
(ff _ANTISPAM_ wegpoetsen uit dit adres natuurlijk)
 
Reply With Quote
 
Bart
Guest
Posts: n/a
 
      02-04-2004
Op Mon, 02 Feb 2004 22:10:17 +0100 schreef "@SM"
<(E-Mail Removed)>:


>If document is not on a server your experencies are of no interest.


Checked it. You're right (that is today, yesterday I checked and it
wasn't. Same file, same Browser). Then again, it's always nice to
blame Bill if my computer behaves badly


However Mozilla 1.2.1 did this allright.
The site I'm working on will be a gift to some friends, and will be on
a CDROM.
(Anyhow most of them use IE, and they will see the proper date. It's
just that I prefer Mozilla, and it would be nice to show the date of
last modification in Mozilla as well...)

Thanks!

Bart

--
Bart Broersma
(E-Mail Removed)
(ff _ANTISPAM_ wegpoetsen uit dit adres natuurlijk)
 
Reply With Quote
 
rgee_f
Guest
Posts: n/a
 
      02-05-2004
Bart <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>. ..
> Op Mon, 02 Feb 2004 22:10:17 +0100 schreef "@SM"
> <(E-Mail Removed)>:
>
>
> >If document is not on a server your experencies are of no interest.

>
> Checked it. You're right (that is today, yesterday I checked and it
> wasn't. Same file, same Browser). Then again, it's always nice to
> blame Bill if my computer behaves badly
>
>
> However Mozilla 1.2.1 did this allright.
> The site I'm working on will be a gift to some friends, and will be on
> a CDROM.
> (Anyhow most of them use IE, and they will see the proper date. It's
> just that I prefer Mozilla, and it would be nice to show the date of
> last modification in Mozilla as well...)
>
> Thanks!
>
> Bart



Bart:

I have run into this problem where the page is displaying the current
time...this is driving me nuts. I read your thread and it looks like
you solved it but am unclear as to how this was done.

I have an external file that looks like this:

var day = new Array
("Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday");

var mon = new Array
("January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December");

var now = new Date();
var last_mod = new Date(document.lastModified);
var mod_month = mon[now.getMonth()];
var mod_date = last_mod.getDate();
var mod_hour = last_mod.getHours();
var mod_minute = last_mod.getMinutes();
var mod_second = last_mod.getSeconds();
var mod_year = last_mod.getYear();
if (mod_year < 2000) {
var mod_year = mod_year + 1900 //because netscape does not evaluate
date properly
}

My html page looks like this:
<html>
<head>
<script src="my_lastModDate.js" type="text/javascript">
</script>
<title>
</title>
</head>
<body>
blah, blah, and more blah...
<SCRIPT TYPE="TEXT/JAVASCRIPT">
<!-- Hide

document.write ("Last modified on: <br>");
document.write (mod_month + " " + mod_date + "\, " + mod_year);
document.write(" " + mod_hour + ":" + mod_minute + ":" +
mod_second);

-->
</SCRIPT>

</body>
</html>

TIA,
rgee_f
 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mozilla pieces versus Mozilla Suite Doug Chadduck Firefox 40 02-12-2006 10:27 PM
Windows Media opening outside Mozilla not in a Mozilla Window Jim Firefox 3 12-17-2005 02:00 AM
CSS Mozilla: Make Mozilla not ignore height style of an inline element Henri HTML 9 02-22-2005 06:08 PM
My CUSTOM Versions Of Mozilla Fiorefox & Mozilla Thunderbird Norvin Adams III Firefox 6 07-13-2004 03:26 PM
mozilla 1.5 from mozilla 1.4 Disco Firefox 6 11-07-2003 04:34 PM



Advertisments