473,322 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Problem with document.lastModified in Mozilla

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
br*********************@tiscali.nl
(ff _ANTISPAM_ wegpoetsen uit dit adres natuurlijk)
Jul 20 '05 #1
12 3194
@SM


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
br*********************@tiscali.nl
(ff _ANTISPAM_ wegpoetsen uit dit adres natuurlijk)


--
******** (enlever/remove [OTER_MOI] du/from reply url) *******
Stéphane MORIAUX : mailto:st*********************@wanadoo.fr
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephane.moriaux/internet/
************************************************** ************
Jul 20 '05 #2
On Mon, 02 Feb 2004 17:34:38 +0100 "@SM" wrote:
<st*********************@wanadoo.fr>:

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
br*********************@tiscali.nl
(ff _ANTISPAM_ wegpoetsen uit dit adres natuurlijk)
Jul 20 '05 #3
Op Sun, 01 Feb 2004 18:30:26 +0100 schreef Bart
<br*********************@tiscali.nl>:

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
br*********************@tiscali.nl
(ff _ANTISPAM_ wegpoetsen uit dit adres natuurlijk)
Jul 20 '05 #4
"Bart" <br*********************@tiscali.nl> wrote in message
news:sm********************************@4ax.com...
<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.
Jul 20 '05 #5
JRS: In article <o4********************************@4ax.com>, seen in
news:comp.lang.javascript, Bart <br*********************@tiscali.nl>
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.
Jul 20 '05 #6
@SM
Bart a ecrit :

On Mon, 02 Feb 2004 17:34:38 +0100 "@SM" wrote:
<st*********************@wanadoo.fr>:

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 : mailto:st*********************@wanadoo.fr
Aide aux Pages Perso (images & couleurs, formulaire, CHP, JS)
http://perso.wanadoo.fr/stephane.moriaux/internet/
************************************************** ************
Jul 20 '05 #7
Op Mon, 2 Feb 2004 18:37:06 -0000 schreef "Richard Cornford"
<Ri*****@litotes.demon.co.uk>:
"Bart" <br*********************@tiscali.nl> wrote in message
news:sm********************************@4ax.com.. .
<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
br*********************@tiscali.nl
(ff _ANTISPAM_ wegpoetsen uit dit adres natuurlijk)
Jul 20 '05 #8
Op Mon, 02 Feb 2004 22:10:17 +0100 schreef "@SM"
<st*********************@wanadoo.fr>:

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
br*********************@tiscali.nl
(ff _ANTISPAM_ wegpoetsen uit dit adres natuurlijk)
Jul 20 '05 #9
Bart <br*********************@tiscali.nl> wrote in message news:<ru********************************@4ax.com>. ..
Op Mon, 02 Feb 2004 22:10:17 +0100 schreef "@SM"
<st*********************@wanadoo.fr>:

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
Jul 20 '05 #10
JRS: In article <bc**************************@posting.google.com >, seen
in news:comp.lang.javascript, rgee_f <ne********@jetable.org> posted at
Thu, 5 Feb 2004 12:47:22 :-

I have run into this problem where the page is displaying the current
time...this is driving me nuts.


Showing all that code is largely pointless - the prime question is "what
does the lastModified string itself hold?".

If it holds some version of the current date/time, even in FFF, then one
cannot hope to re-interpret it as anything else.

If it holds a date/time equivalent to 1970-01-01 00:00:00 GMT, even in
FFF, then one cannot hope to re-interpret it as anything else.

If it holds a date/time which is reasonable for a Web page, i.e. after
TB-L's invention but appreciably before current, even in FFF, then one
can hope to re-interpret it as a respectable representation of that.

The re-interpretation code can, and should, be tested independently, on
other date strings of expected formats,

BTW, what happens with pages generated dynamically on the server - do
they have a Last-Modified header representing the instant of generation,
or something else, or not?

--
© 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.
Jul 20 '05 #11
Dr John Stockton <sp**@merlyn.demon.co.uk> wrote in message news:<v1**************@merlyn.demon.co.uk>...
JRS: In article <bc**************************@posting.google.com >, seen
in news:comp.lang.javascript, rgee_f <ne********@jetable.org> posted at
Thu, 5 Feb 2004 12:47:22 :-

I have run into this problem where the page is displaying the current
time...this is driving me nuts.


Showing all that code is largely pointless - the prime question is "what
does the lastModified string itself hold?".

If it holds some version of the current date/time, even in FFF, then one
cannot hope to re-interpret it as anything else.

If it holds a date/time equivalent to 1970-01-01 00:00:00 GMT, even in
FFF, then one cannot hope to re-interpret it as anything else.

If it holds a date/time which is reasonable for a Web page, i.e. after
TB-L's invention but appreciably before current, even in FFF, then one
can hope to re-interpret it as a respectable representation of that.

The re-interpretation code can, and should, be tested independently, on
other date strings of expected formats,

BTW, what happens with pages generated dynamically on the server - do
they have a Last-Modified header representing the instant of generation,
or something else, or not?

John:

Thanks for the reply. As far as I can tell the lastModified string is
hoding current and time. I am sorry but I really feel stupid because
I really do not quite understand your three above 'if'
statements...When I run my lastModified code and press the reload
button I can see the seconds ticking away. If I leave the page alone
for a day it will display the current date and time. I went to your
page and am still unclear if this is a coding problem or a server
problem, in that the server is not sending HTTP header data back to
the browser...

TIA.
rgee_f
Jul 20 '05 #12
JRS: In article <bc**************************@posting.google.com >, seen
in news:comp.lang.javascript, rgee_f <ne********@jetable.org> posted at
Mon, 9 Feb 2004 08:55:09 :-
Thanks for the reply. As far as I can tell the lastModified string is
hoding current and time. I am sorry but I really feel stupid because
I really do not quite understand your three above 'if'
statements...When I run my lastModified code and press the reload
button I can see the seconds ticking away. If I leave the page alone
for a day it will display the current date and time. I went to your
page and am still unclear if this is a coding problem or a server
problem, in that the server is not sending HTTP header data back to
the browser...

A confusing report.

What you need to do is to put the following code on your server at a
known time of day, wait for at least a few times as long as the largest
possible difference between server time and real time, then fetch the
page and show us the exact result, the time of upload, and the time of
fetch.

You need also to say, unless looking at the result tells you all you
need to know, how your own local time differs from GMT; and, in case
your server is wrongly configured, it could be useful to know server's
local time difference from GMT. Always give locality information in any
case where it may matter.

<script>
document.write('Result: "', document.lastModified, '"')
</script>

Using my test page locally, I get Result: "02/09/04 19:53:54" which
is, in American, exactly when the page was changed.

I expect that the string will always represent a GMT time, and that it
may contain the letters GMT.

You may get the time of upload by the server clock, the time of fetch by
your computer's clock, "0", "", or something unpredictable (I don't
expect "0" or "", if I understand you correctly.

There is NO POINT in examining this string with any more code until the
string itself is understood.
You could, of course, also tell us all the URL of the page, so that we
can look at it.
IIRC, you can check the page with http://malch.elsop.com/quick.cgi -
IIRC, the full report includes the headers, and may show a Last
Modified: line.

--
© 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.
Jul 20 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John Norvell | last post by:
I just noticed that recently the javascript I was using to format and display the last modified date of my web page is always reporting the current date instead. It used to work fine. This is true...
2
by: Kam Bansal | last post by:
Hi all, We're using Apache 1.3 (I know, I know, there's a newer version...) and it seems that the document.lastModified does not return the correct date. On Netscape it shows 01/01/1970 and on...
1
by: Ryan Stewart | last post by:
If you don't want to read this post because of its length, I understand. I've spent two and a half days on this problem and have a good deal of information to relate. And this is kind of a long...
17
by: JellyON | last post by:
Hi. How to do document.lastModified works with Netscape and Opera ? Or what other way to take to simply display the last update date about current page ?
14
by: Rene Grothmann | last post by:
I have managed to communicate between forms and Java applets. A button press sends the content of the text area to an applet, a second button gets some text from the applet and puts it into the...
1
by: Jeff Silverman | last post by:
I have a PHP program that almost works. I'm running it from the command line and simulating a form using a GET method. That part is working, but I get spurious records with all of the fields...
15
by: Cerebral Believer | last post by:
Hi all, I am a newbie to JavaScript and am just trying to get a script going that will write the ful date and time to each webpage as it is viewed. Can anyone point out what mistakes there are...
1
by: perdoname | last post by:
Hello, Im trying to implement a program which will split a text file and then parses the elements to an arraylist. My text file looks like that: My program is that: public class Parse {
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.