...

View Full Version : Last Modified Date From Different File (Help Please)



tunayx
08-18-2008, 06:07 PM
Hi, I have main html page called "ana.html" which seldomly updated and another page "yeniler.html" that showing latest added articles and often updated. What I want is, whenever "yeniler.html" modified the javascript in "ana.html" shows "Latest Update Date: xx.xx.xxxx".

As you can see I don't want to show file modified date of "ana" in "ana" like so many scripts offer on the web , but in page "ana" modified date of "yeniler"

I also want the date format like 8.18.2008 (without hour, minute, and name of the month)

Philip M
08-18-2008, 06:18 PM
I think you will need a server-side script or AJAX for this.

Or possibly yeniler writes a cookie containing the last update which ana can read (if ana is in the same domain).

tunayx
08-18-2008, 06:22 PM
My server supports php but can I add php inside of my main html page?

Philip M
08-18-2008, 06:24 PM
My server supports php but can I add php inside of my main html page?

Yes, of course.


<?php

// Change to the name of the file
$last_modified = filemtime("thisfile.php");

// Display the results
// eg. Last modified Monday, 27th October, 2003 @ 02:59pm
print "Last modified " . date("l, dS F, Y @ h:ia", $last_modified);

?>

You could also try this:-


<script type= "text/javascript">
myActiveXObject = new ActiveXObject("Scripting.FileSystemObject");
file = myActiveXObject.GetFile("c:\\test.txt");
alert(file.DateLastModified);
</script>

Cranford
08-18-2008, 07:00 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Any Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript">

function init(){

var modifiedStr = window.frames['currentArticles'].document.lastModified;
modifiedStr = modifiedStr.replace(/\//g,".").substring(0,11);
document.getElementById('updateMsg').innerHTML = "Last modified on: " + modifiedStr;
}

onload = init;

</script>
<style type="text/css">

body {background-color: #eae3c6; margin-top: 60px;}
iframe {display: none;}
#updateMsg {font-family: arial; font-size: 14pt; color: blue; background-color: #f0fff0; padding: 3px; width: 350px; text-align: center; margin-left: auto; margin-right: auto;}

</style>
</head>
<body>
<iframe name="currentArticles" src="./yeniler.html"></iframe>
<div id="updateMsg" class="updateMsg"></div>
</body>
</html>

tunayx
08-18-2008, 07:30 PM
Phillip: javascript gives error and didn't work for me. Php works fine as standalone but how can I insert it to a layer to position it on my html, using frontpage?

Cranford: Your worked standalone page but same trouble how can I insert it to a layer so I can position it on my html using frontpage?

Cranford
08-18-2008, 07:38 PM
The info is already in a DIV. Use CSS to position the DIV.

I set the DIV's class to #updateMsg

Include in that class, positioning info, and delete the margin settings

e.g.: position-top: 300px; position-left: 50px;

#updateMsg {font-family: arial; font-size: 14pt; color: blue; background-color: #f0fff0; padding: 3px; width: 350px; text-align: center; position-top: 300px; position-left: 50px;}

tunayx
08-18-2008, 08:34 PM
Now another trouble, updated date (Cranford your code) stayed behind the picture (I want put it to right below on my main picture. I also can't replace #updateMsg, get script errors. I've sent my whole page, I have text "Put Date Here" can you place date there.

Text too big to add the reply.

http://rapidshare.com/files/138289204/ana.txt.html

Cranford
08-18-2008, 08:37 PM
Post your question in the CSS forum. I never look at links, and I don't have time to customize the code for you.

tunayx
08-18-2008, 09:09 PM
Admin can delete this thread then, thanks.

rnd me
08-19-2008, 09:08 AM
try searching (http://www.codingforums.com/showthread.php?t=146145)

tunayx
08-19-2008, 12:59 PM
I found a solution from another site, if anybody needs here:


<html>
<head>
<title>Last Modified</title>
<script type="text/javascript">
function getLastMod(){
var myFrm = document.getElementById('myIframe');
var lastModif = new Date(myFrm.contentWindow.document.lastModified);
document.getElementById('LastModified').innerHTML = "Prices correct as at: " + lastModif.toLocaleString();
}
</script>
</head>
<body>
<span id="LastModified"></span>

<iframe id="myIframe" onload="getLastMod()" src="prices.txt" style="display:none;">
</iframe>

</body>
</html>

janbastiaanssen
09-09-2008, 09:54 PM
Anybody an idea how to thange the output of this script into for example 25-12-2007
I dont know anything about Java.
Thanks.


I found a solution from another site, if anybody needs here:


<html>
<head>
<title>Last Modified</title>
<script type="text/javascript">
function getLastMod(){
var myFrm = document.getElementById('myIframe');
var lastModif = new Date(myFrm.contentWindow.document.lastModified);
document.getElementById('LastModified').innerHTML = "Prices correct as at: " + lastModif.toLocaleString();
}
</script>
</head>
<body>
<span id="LastModified"></span>

<iframe id="myIframe" onload="getLastMod()" src="prices.txt" style="display:none;">
</iframe>

</body>
</html>

Philip M
09-10-2008, 08:38 AM
Be aware that Java and Javascript are entirely different programming languages, in spite of the confusingly similar names.


<html>
<head>
<title>Last Modified</title>
<script type="text/javascript">
function getLastMod(){
var myFrm = document.getElementById('myIframe');
var lastModif = new Date(myFrm.contentWindow.document.lastModified);
var yr = lastModif.getYear();
var mm = lastModif.getMonth()+1;
if (mm <10) {mm = '0'+ mm}
var dt = lastModif.getDate();
if (dt <10) {dt = '0' + dt}
var lmDate = dt +"-" + mm + "-" + yr;
document.getElementById('LastModified').innerHTML = "Prices correct as at: " + lmDate;
}
</script>
</head>
<body>
<span id="LastModified"></span>

<iframe id="myIframe" onload="getLastMod()" src="prices.txt" style="display:none;">
</iframe>

</body>
</html>


Wednesday, the ladies Liturgy society will meet. Mrs. Jones will sing "Put me in my little bed" accompanied by the pastor. - Church bulletin.

janbastiaanssen
09-12-2008, 01:53 PM
Thanks again Philip.

When I try to call this function several times on one page only the first one gives result. Any idea why ??

<html>
<head>
<title>Last Modified</title>
<script type="text/javascript">

<!-- tbv datum update
function getLastMod()
{
var myFrm = document.getElementById('myIframe');
var lastModif = new Date(myFrm.contentWindow.document.lastModified);
var yr = lastModif.getYear();
if (yr < 2000) {yr=yr+1900}
var mm = lastModif.getMonth()+1;
if (mm <10) {mm = '0'+ mm}
var dt = lastModif.getDate();
if (dt <10) {dt = '0' + dt}
var lmDate = dt + "-" + mm + "-" + yr;
document.getElementById('LastModified').innerHTML = " Update: " + lmDate;
}
</script>
</head>
<body>
<span id="LastModified"></span>
<iframe id="myIframe" onload="getLastMod()" src="van gastel.html" style="display:none;">
</iframe>
<br>
<br>
<span id="LastModified"></span>
<iframe id="myIframe" onload="getLastMod()" src="ermen.html" style="display:none;">
</iframe>
<br>
<br>
<span id="LastModified"></span>
<iframe id="myIframe" onload="getLastMod()" src="bastiaanssen.html" style="display:none;">
</iframe>
</body>
</html>

Philip M
09-12-2008, 04:53 PM
Thanks again Philip.

When I try to call this function several times on one page only the first one gives result. Any idea why ??




Because you cannot have three elements (iframes) all with the same id.

shadezz
08-11-2009, 03:48 PM
Hey Philip, the php script works when the files are online but the java didnt work


Yes, of course.


<?php

// Change to the name of the file
$last_modified = filemtime("thisfile.php");

// Display the results
// eg. Last modified Monday, 27th October, 2003 @ 02:59pm
print "Last modified " . date("l, dS F, Y @ h:ia", $last_modified);

?>

You could also try this:-


<script type= "text/javascript">
myActiveXObject = new ActiveXObject("Scripting.FileSystemObject");
file = myActiveXObject.GetFile("c:\\test.txt");
alert(file.DateLastModified);
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum