document.lastModified

J

JellyON

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 ?
 
V

VK

JellyON said:
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 ?

document.lastModified supported since JavaScript 1.0 by all ever
existed / existing browsers (including Netscape and Opera) - so I don't
see where could be any problem.

If you are looking for a way to display the date nicely on the page,
then something like:

<html>
<head>
<title>Last Modified</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">

<script type="text/javascript">

function showLastModified() {
var out = document.getElementById('lastModified');
var d = new Date();
if (d.toLocaleDateString) {
out.innerHTML = d.toLocaleDateString(document.lastModified);
}
else {
out.innerHTML = document.lastModified;
}
}

window.onload = showLastModified;
</script>

</head>

<body>

<p id="lastModified">&nbsp;</p>

</body>
</html>
 
E

Evertjan.

VK wrote on 15 nov 2005 in comp.lang.javascript:
document.lastModified supported since JavaScript 1.0 by all ever
existed / existing browsers (including Netscape and Opera) - so I don't
see where could be any problem.

A warning should be in place,
that "asp-pages" [and probably also "php-pages"]
are constructed/rendered HTML new(!!!!) every time,
so that the ever changing document.lastModified,
while being correct, is not very usefull.
 
V

VK

Evertjan. said:
A warning should be in place,
that "asp-pages" [and probably also "php-pages"]
are constructed/rendered HTML new(!!!!) every time,
so that the ever changing document.lastModified,
while being correct, is not very usefull.

A good point!
I guess formally it's correct (?) because document.lastModified
indicates when the *content* of document has been last time changed.
And in case of ASP it happened during the parsing on the server-side.
Maybe it's time to introduce some new property like
lastTemplateModified ? :)

Microsoft suggests in such case to set Last-Modified header explicetly
in the server response:
<http://support.microsoft.com/kb/q165862/>

Seems like a nice workaround?
 
E

Evertjan.

VK wrote on 15 nov 2005 in comp.lang.javascript:
Evertjan. said:
A warning should be in place,
that "asp-pages" [and probably also "php-pages"]
are constructed/rendered HTML new(!!!!) every time,
so that the ever changing document.lastModified,
while being correct, is not very usefull.

A good point!
I guess formally it's correct (?) because document.lastModified
indicates when the *content* of document has been last time changed.
And in case of ASP it happened during the parsing on the server-side.
Maybe it's time to introduce some new property like
lastTemplateModified ? :)

I like that.
Microsoft suggests in such case to set Last-Modified header explicetly
in the server response:
<http://support.microsoft.com/kb/q165862/>

No, that is only for older IIS versions giving an unreadable value:

"SYMPTOMS
The lastModified property that the Internet Explorer HTML scripting
object model exposes indicates the date and time at which the sender
believes the resource was last modified. When this property is referenced
in a page that the Active Server Page (ASP) framework generates, the
client browser displays an unreadable value."

The date is stil refreshed every time.

http://www.tutorial-web.com/asp/fso/file.asp?property=DateLastModified

FSO can find the date serverside, I hope, and then the header could be
set as indicated by MS?
 
T

Thomas 'PointedEars' Lahn

JellyON said:
Hi. How to do document.lastModified works with Netscape and Opera ?

It works within the limits of transmitted HTTP headers. Nothing has to
be done.
Or what other way to take to simply display the last update date about
current page ?

Use reliable server-side scripting, not unreliable client-side one,
e.g. Server-side JavaScript, ASP with JScript or, as here, PHP:

<?php echo date('Y-m-d\TH:i:sO', @filemtime($sFile)); ?>

where $sFile is the filename string or a constant like `__FILE__'.


PointedEars
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated
Tue, 15 Nov 2005 08:20:28, seen in JellyON
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 ?


Be warned that some software gives lastModified as an FFF string with a
two-digit year, even when set for a non-FFF locality (FFF is used in US;
perhaps part of CA; and probably, alas, now Iraq).

If the string is numeric and displayed directly, the user may be able to
deduce which is year, which is month, and which is day; it can be done
reliably for 11/16/05, but not for 03/04/05.

IMHO, the best way is to type the date into the HTML when you modify the
page. That has the additional advantage of not changing if the page is
reloaded for any reason that does not affect the reader.


See below.
 
J

JellyON

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 ?
OK, thanks all. Effectively, it works under NN and Opera too : it was
just a matter of DIV position which masked the white font on a white
background :-(
 
J

John W. Kennedy

Dr said:
IMHO, the best way is to type the date into the HTML when you modify the
page. That has the additional advantage of not changing if the page is
reloaded for any reason that does not affect the reader.

For whatever it's worth, I've been doing the same thing for a copyright
line, and have had no practical problem with

year = new Date (document.lastModified).getFullYear ();

on Firefox, IE6, Opera, or Safari.

--
John W. Kennedy
"But now is a new thing which is very old--
that the rich make themselves richer and not poorer,
which is the true Gospel, for the poor's sake."
-- Charles Williams. "Judgement at Chelmsford"
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Sun, 20 Nov 2005
20:24:06, seen in John W. Kennedy
For whatever it's worth, I've been doing the same thing for a copyright
line, and have had no practical problem with

year = new Date (document.lastModified).getFullYear ();

on Firefox, IE6, Opera, or Safari.

It gives me 1905, for a page last changed on 2005-11-19, on which

new Date (document.lastModified) -> Sun Nov 19 23:14:10 UTC 1905

The string is 11/19/05 23:14:10 which is of course FFF and neither
ISO nor EU field order. However, even before the 13th of a month, new
Date(string) has a matching error.

Never assume that, just because American-originated software often works
correctly for Americans in America, that it works equally correctly, or
even consistently, otherwise.
 
J

John W. Kennedy

Dr said:
JRS: In article <[email protected]>, dated Sun, 20 Nov 2005
20:24:06, seen in John W. Kennedy


It gives me 1905, for a page last changed on 2005-11-19, on which

new Date (document.lastModified) -> Sun Nov 19 23:14:10 UTC 1905

The string is 11/19/05 23:14:10 which is of course FFF and neither
ISO nor EU field order. However, even before the 13th of a month, new
Date(string) has a matching error.

Never assume that, just because American-originated software often works
correctly for Americans in America, that it works equally correctly, or
even consistently, otherwise.

1) As far as I can tell, there is no format specified for lastModified.

2) But RFC 1123 is specified for HTTP last-modified.

3) My server correctly uses RFC 1123.

4) Every browser I have tested with my server puts RFC 1123 into
lastModified.

5) It would appear to be the case that most, very likely all, browsers
copy last-modified directly to lastModified.

6) I don't see how the above nonstandard string is getting into the
situation at all, unless you are working with a nonconformant server.

--
John W. Kennedy
"But now is a new thing which is very old--
that the rich make themselves richer and not poorer,
which is the true Gospel, for the poor's sake."
-- Charles Williams. "Judgement at Chelmsford"
 
V

VK

Dr said:
Never assume that, just because American-originated software often works
correctly for Americans in America, that it works equally correctly, or
even consistently, otherwise.

Eh?

As it was well explained to you, Last-Modified content header has a
well specified and internationally accepted format. A quick check
across domains would show it to you:
(using AjaxToolbox from <http://www.ajaxtoolbox.com>,
getResponseHeader, time is replaced for consistency)

http://www.merlyn.demon.co.uk/index.htm

Last-Modified: Wed, 16 Nov 2005 HH:MM:SS GMT
document.lastModified: 11/25/2005 HH:MM:SS

http://www.geocities.com/schools_ring/ArrayAndHash.html
Last-Modified: Fri, 25 Nov 2005 HH:MM:SS GMT
document.lastModified: 11/25/2005 HH:MM:SS

The content header is uniform trasport format, and
document.lastModified is set based on this header using your system
locale. You don't need to bother what format for Content-Header is used
as you don't need to bother how many bytes contained in TCP/IP packets
used do deliver this particular page.

That's really ...stupid to try to find a national issues in a
*transport format*. Yes, Internet (Arpanet) was originally made by
Americans and for Americans so you cannot blame on them that used their
standards and not say Chinese Lunar Calendar (no offense to China). But
as it was said, transport format is used only to deliver data to
client, so computer could use a known pattern to re-format it. Unless
you specially apply yourselve you will never see the original transport
form.

So concerning year 2005 which becomes year 1005 or so on "your"
computer: it's time to reinstall ;-)
 
J

John G Harris

2) But RFC 1123 is specified for HTTP last-modified.
<snip>

RFC 2068, which supersedes 1123, says that browsers MUST accept all
three of these date formats :

Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format

Notice the '94' horror.

John
 
J

John G Harris

As it was well explained to you, Last-Modified content header has a
well specified and internationally accepted format.
<snip>

Well, well. Here's VK quoting a published standard, one where some of
the committee members are academics.

We never thought to see the day!

John
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated Thu, 24 Nov 2005
16:23:43, seen in John W. Kennedy
1) As far as I can tell, there is no format specified for lastModified.
Agreed.

2) But RFC 1123 is specified for HTTP last-modified.
Agreed.

3) My server correctly uses RFC 1123.

That seems very likely.
4) Every browser I have tested with my server puts RFC 1123 into
lastModified.

Then test more browsers. Or read the newsgroup FAQ.
5) It would appear to be the case that most, very likely all, browsers
copy last-modified directly to lastModified.

Perhaps; but not all.
6) I don't see how the above nonstandard string is getting into the
situation at all, unless you are working with a nonconformant server.

It is what the browser gives, both when reading from the server I use
for my pages (and AFAIR for all other servers) and when reading from the
local disc. "My" server is undoubtedly compliant.


BTW, the header line is, by RFC, in English; you seem to be American,
and so have a system configured for a form of English. It occurs to me
that in a system configured for non-English, javascript lastModified
*might* be localised and use non-English words.
 
D

Dr John Stockton

JRS: In article <[email protected]>
, dated Fri, 25 Nov 2005 02:57:51, seen in VK
Eh?

As it was well explained to you, Last-Modified content header has a
well specified and internationally accepted format. A quick check
across domains would show it to you:
(using AjaxToolbox from <http://www.ajaxtoolbox.com>,
getResponseHeader, time is replaced for consistency)

IRRELEVANT. I'm referring to javascript lastModified, not the header
string; the header string is specified by an RFC and I have no knowledge
of any servers giving a non-compliant form.

http://www.merlyn.demon.co.uk/index.htm

Last-Modified: Wed, 16 Nov 2005 HH:MM:SS GMT

Should be about that; approx. 18:42 GMT.
document.lastModified: 11/25/2005 HH:MM:SS

That's US format, and the wrong date. Your browser has not copied the
transport string.

http://www.geocities.com/schools_ring/ArrayAndHash.html
Last-Modified: Fri, 25 Nov 2005 HH:MM:SS GMT
document.lastModified: 11/25/2005 HH:MM:SS

Your browser has not copied the transport string.
The content header is uniform trasport format, and
document.lastModified is set based on this header using your system
locale.

It is set based on the value of the date in the header, agreed.

You don't need to bother what format for Content-Header is used
as you don't need to bother how many bytes contained in TCP/IP packets
used do deliver this particular page.

That's really ...stupid to try to find a national issues in a
*transport format*. Yes, Internet (Arpanet) was originally made by
Americans and for Americans so you cannot blame on them that used their
standards and not say Chinese Lunar Calendar (no offense to China). But
as it was said, transport format is used only to deliver data to
client, so computer could use a known pattern to re-format it. Unless
you specially apply yourselve you will never see the original transport
form.

But I was not referring to the transport form; that is satisfactory
although not wisely chosen (it should be ISO 8601, but the US ignores
that apart from making it (AIUI) a Federal standard).
So concerning year 2005 which becomes year 1005 or so on "your"
computer: it's time to reinstall ;-)

I assure you that it is my computer; I recall purchasing it with my own
money.
 
V

VK

John said:
Well, well. Here's VK quoting a published standard, one where some of
the committee members are academics.

We never thought to see the day!

<offtopic of document.lastModified>

You mean you've found in my postings a call to an anarchie? Nothing
more wrong than that - in standards I'm more a follower of a
distatorship. ;-)

As you may noticed already I'm a Nietzsche follower in this domain: "A
strong makes the rules - a weak has to follow them".
* where [this domain] means business and business standards
exclusively*

It's the end of the year 2005 and still many of so-called "browsers"
fail to pass the basic IQ test of ECMA 262 written at the end of 1999.
Do they need another 6 years to finish the primary school? Business is
not a schools for special children where the class doesn't advance
until the last in the class got the material. It's more of the Ivy
Leage - everyone has to rush to keep up with the leader.

JavaScript 1.5 / JScript 5.5 are standards in use for several years
already. Others have to support *at least* ECMA 262 so we could skip on
them gracefully. The most difficult mental cases (like Konqueror 1.x)
are out of any help which community could provide them.
<offtopic>
 
J

John W. Kennedy

John said:
<snip>

RFC 2068, which supersedes 1123,

No, RFC 2068 is a specification of HTTP 1.1 (obsoleted by RFC 2616), the
other is a date format.
says that browsers MUST accept all
three of these date formats :

Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format

Notice the '94' horror.

RFC 2068 and RFC 2616 both say that, although a browser must accept any
of those forms, a server must send only the RFC 1123 format.

In any case, I am concerned only with my own server, which /does/ send
the RFC 1123 format.

--
John W. Kennedy
"But now is a new thing which is very old--
that the rich make themselves richer and not poorer,
which is the true Gospel, for the poor's sake."
-- Charles Williams. "Judgement at Chelmsford"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top