Click to See Complete Forum and Search --> : NEEDED: last modified script to show on different page


Gaby
03-21-2004, 10:03 AM
Hi. I need a script so that I can show the last time I updated the files on my site. The thing is, I want it to show on a different page.

Like for example, I have a page I'll hypothetically name test.htm and I last modified it on yesterday. I have another file called test2.htm and that was last modified on Thursday. And finally there is a third page I'll call test3.htm and on that page I have links to test.htm and test2.htm

Also on test3.htm, I have a column where it says "Last Update" and I want a JS code so that I can show that test2.htm was updated 01/18/2004 and test.htm was updated 01/20/2004

Is there a way I can do this? I already know the code to say last modified on such and such date if, for example, I want to say on test.htm, that it was last updated on 1/20/2004

By the way, I want the date in that format.

I hope someone can help. Thanks for any help.

Gaby

steelersfan88
03-21-2004, 11:36 AM
i *think* your only option is to use a server side language in which the last modified time is updated on the server and any page can retrieve the contents of the file holding that date.

Your other option would be to place that into a div or span (the last updated) and include a hidden frame of it.

Then you could use:var lastUpdate = parent.frames['frame name/number'].getElementById('id of span or div').innerHTML

Gaby
03-22-2004, 08:01 AM
OK. I totally do not get that. Could you explain that in a different way, perhaps?

Gaby

steelersfan88
03-22-2004, 02:00 PM
With Javascript, the only way that I could image in possible if the data of the last updated was stored in a span object:<span id="update">Last Updated: DD/MM/YY</spa>(date in any format). Then, on another page that you want to retrieve this information, add:<iframe src="page with span on it" height="1" width="1" style="position:absolute;,left:-100;top:-100"> </iframe>To receive it, you would use:[variable] = parent.frames[0].getElementById('update').innerHTMLWhere variable refers to an element on the page or any variable. Note, this will only work after the page has completely loaded (assuming it works at all, haven't tried it yet)!

Gaby
03-23-2004, 01:41 PM
I tried this but nothing. Perhaps I'm putting the codes in the wrong places?

Could someone try what steelersfan88 gave and tell me if they got it to work?

Gaby

PS. If it's not possible w/ JS, what could I use?

steelersfan88
03-23-2004, 02:00 PM
It worked for me. Here is what the page designs should look like:


Page with Last Updated:<html>
<!-- content -->
<span id="update"> Last Updated 03/23/04 </span>
<!-- content -->
</html>That of course can be written in, but before page loads.

Page to Receive Info:<html>
<!-- content -->
<body onload="document.getElementById('update').innerHTML = parent.frames[0].document.getElementById('update').innerHTML">
<span id="update"> Last Updated </span>
</body>
<!-- content -->
</html>
The only problem in my previous code was forgetting document. before getElementById. That should work!

Gaby
03-24-2004, 02:38 PM
Should there be any other info on the pages? I made two pages w/ those codes and it didn't work.

And why do you write PHP? Do I need that as the extension or the script language?

Please answer.

Gaby

steelersfan88
03-24-2004, 03:16 PM
It is not PHP, it is simply the tags we use to improve the readability of our code. The extension can be as simple as .htm(l). The code should work, if you are correctly placing the last update dinto the span object as I previously showed.

Do you have a link to where I can see the problem? And what browser are you running?

ALSO, note: the two files must be located on the same domain name, and should be in the same directory (yet the second should not cause a problem)

Gaby
03-25-2004, 04:19 PM
I will try to post a link to tomorrow to show my problem. (Then I'm going to my mom's and she doesn't have internet -- will be back a week from Sunday night) And also, I am going to need to have different directories. Will that be a problem?

I use IE. 4, I think on my laptop. 6 on computer w/ internet.

Gaby

ETA: Do I need the iframe you gave earlier?

steelersfan88
03-25-2004, 05:04 PM
yes, you also, as now edited since I did not include it, need the iframe. Navigating beteen directories should not be a problem, although I've never tried it and I want to precaution you of *possible* results. The code for each is shown below:
Page to Hold Info:
<html>
<!-- content -->
<span id="update"> Last Updated 03/23/04 </span>
<!-- content -->
</html>That of course can be written in, but before page loads.

Page to Receive Info:<html>
<!-- content -->
<body onload="document.getElementById('update').innerHTML = parent.frames[0].document.getElementById('update').innerHTML">
<iframe src="page with span on it" height="1" width="1" style="position:absolute;,left:-100;top:-100"> </iframe>
<span id="update"> Last Updated </span>
</body>
<!-- content -->
</html>

Gaby
03-26-2004, 01:46 PM
steelersfan88,

I got it to work but I can't seem to figure how to make it work for more than one file. Meaning, I want one page to show the last updates of several pages which are updated on different days. I think all I need is how to make there be more than one part to the "onload" part of the <BODY> tag. The only one that shows up is the one I list first in that part. But, of course, it could be more complicated than that. I don't know..

Gaby

steelersfan88
03-26-2004, 02:09 PM
well, as many frames as you need, and as many iframes. Then make it like:<!-- This is NOT PHP -->

<script type="text/javascript">

function forLoad(numObjects) {
// name your span objects update0, update1, update2, ...
// start at zero, when sending number total, send one more
// >> than last nbumber, if update1, then send 2

//name the span update on the form of which you want to
// receive the information
for(var i=0;i<numObjects;i++) {
document.getElementById('update'+ i).innerHTML = parent.frames[i].document.getElementById('update').innerHTML
}
}

</script>

<body onload="forLoad("Enter Number of Total Updates To Receive")">Note, on the page with the last updated on it, name that span update. On the page to receive multiple spans, name them update0,update1,... When sending number of total updates, send one more than the last number. If you have update0, update1, and update2, then send 3.

Of course, you will need all the iframes in the order that you want to receive them on the page, and the span objects with the ids matching the frame number.

Gaby
03-26-2004, 02:13 PM
Thanks.. I knew something needed to be done but what it was I didn't know.. So thanks again..

Gaby

steelersfan88
03-26-2004, 02:14 PM
did it end up working?

Gaby
04-16-2004, 07:52 PM
Yes, it works wonderfully. Thank you so much!!

Gaby

steelersfan88
04-16-2004, 09:22 PM
I am very glad things worked out !!!

Gaby
04-17-2004, 11:51 AM
Well, the pages that I had with many loads (like the most was like 42) took a while for the page to load. I learned some PHP from another internet friend and that takes a lot less time. but i use the code on pages where i only need one or two.

btw, do you know why php doesn't work offline? at least it doesn't on my laptop. it works fine online.

Gaby

steelersfan88
04-17-2004, 03:35 PM
PHP is done server side, which means a server processes the script and then runs it. Locally, you do not have a server to process it, so the script is just displayed unprocessed :)