Further to the date last updated thread

A

Ade

Hi,

I posted a similar question a couple of months ago but didn't get anywhere
near the amount of responses as that last thread but what i did get was very
useful to me so thanks for that.

In addition to obtaining the date last updated, I wanted to update a
particular frame on my page with the information from the file being loaded
into the pages 'main' frame. I put a link to the following function in every
page that may be loaded into the main frame with an onLoad="show_updated();"
in the <body> tag...

function show_updated()
{
dm = new Date (document.lastModified);
str_months = "JanFebMarAprMayJunJulAugSepOctNovDec";
offset = dm.getMonth() * 3;
this_month = str_months.substring(offset,offset+3);
hr = dm.getHours();
mn = dm.getMinutes();
pm = "am";
if (mn < 10) mn = "0" + mn;
if (hr > 11) pm = "pm";
txt = ("Page updated: <br>" + dm.getDate() + "-" + this_month
+ "-" + dm.getFullYear() + " " + hr + ":" + mn + pm);

window.top.UPDATED.document.getElementById("dateupdated").innerHTML = txt;
}

Sometimes it works and sometimes it doesn't. When it fails, it generally
shows the current date and time (??). I can't be any more specific I'm
afraid. Can anybody suggest why or suggest a better way of attempting this?

Thanks,

Ade
 
E

Evertjan.

Ade wrote on 17 aug 2007 in comp.lang.javascript:

var dm = new Date (document.lastModified);
Sometimes it works and sometimes it doesn't. When it fails, it
generally shows the current date and time (??).

Why do you think it 'fails', if you get such results?

1 If it is an asp page, the page is constructed on the spot and the
lastModified will be serverside "now". [probably the same with php, etc.]

2 if document.lastModified == '' then you will get local 'now' of the
client.
 
A

Ade

Thanks for the quick response,

Why do you think it 'fails', if you get such results?

I know when the pages were uploaded to my ISP so the files should show dates
prior to today.

I am not a very experienced web designer and know very little about the
technologies used to create web pages. I am from a VMS background and more
used to cobol, c, fortran and the like. I am using simple hand-written HTML
and javascript more as a learning exercise really. ASP is well beyond my
capabilities and probably will be for some time to come. I'd like to create
a feedback form for the same project but that will have to wait for a while.

I have noticed today that the dates work when testing on my local machine
but not when uploaded to my ISP. I think, therefore, it's some sort of read
protection problem and not a javacript one. Any comments you have on this
would be appreciated, if not a little out of the context of this newsgroup.

Just out of interest, using the Safari browser as a test fails to load the
frame at all - at least IE and FF manage to do that.

Thanks again,

Ade
 
D

Dr J R Stockton

In comp.lang.javascript message <[email protected]
er.co.uk>, Fri, 17 Aug 2007 13:01:06, Ade <adrian.nospam.birkett@blueyon
der.co.uk> posted:
pm = "am";
if (mn < 10) mn = "0" + mn;
if (hr > 11) pm = "pm";
txt = ("Page updated: <br>" + dm.getDate() + "-" + this_month
+ "-" + dm.getFullYear() + " " + hr + ":" + mn + pm);

Normally, one uses either the 24-hour clock or an am/pm indicator, but
not both.

An equivalent way of setting the indicator is
pm = hr<12 ? "am" : "pm"

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 

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,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top