Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Last modified script showing last visited?

Status
Not open for further replies.

jaslr

Programmer
Aug 16, 2001
67
AU
I post the following script to show a last modified notice on a few pages in my site. But whenever I refresh it shows the last visited date/time not the last modified.


What could be happening?

<script language=&quot;JavaScript&quot;>
var lastMod = document.lastModified;
document.write(&quot;This page was last updated on the &quot; + reArrange(lastMod) + &quot;&quot;);
document.close();

function reArrange(sDate ,bTime){
var dateElements = sDate.split(&quot;/&quot;);
if(bTime)dateElements[2] = dateElements[2].split(&quot; &quot;) + [0];
else{}
var newDate = dateElements[1] + &quot;/&quot; + dateElements[0] + &quot;/&quot; + dateElements[2];
return newDate;
}
</script>

 
Actually I think it happens because the page is an asp not an html, because it does work on html pages.

Why doesn't it work on asp pages?

Regards
jaslr
 
here is the script that i use sometimes:

<script language=&quot;JavaScript&quot;>
//<!--
function getLongDateString()
{ //method defined on class Date.
//Returns a date string of the form: Day DD Month,YYYY
//(e.g. Sunday 27 September, 1998)
monthNames = new Array(&quot;January&quot;,&quot;February&quot;,&quot;March&quot;,&quot;April&quot;,&quot;May&quot;,&quot;June&quot;,&quot;July&quot;,&quot;August&quot;,&quot;September&quot;,&quot;October&quot;,&quot;November&quot;,&quot;December&quot;);
dayNames = new Array(&quot;Sunday&quot;,&quot;Monday&quot;,&quot;Tuesday&quot;,&quot;Wednesday&quot;,&quot;Thursday&quot;,&quot;Friday&quot;,&quot;Saturday&quot;);
dayOfWeek = this.getDay();
day = dayNames[dayOfWeek];
dateOfMonth = this.getDate();
monthNo = this.getMonth();
month = monthNames[monthNo];
year = this.getYear();
if (year < 2000)
year = year + 1900;
dateStr = day+&quot; &quot;+dateOfMonth+&quot; &quot;+month+&quot;, &quot;+year;
return dateStr;
}
//register the method in the class Date
Date.prototype.getLongDateString=getLongDateString;

function DocDate()
{ //return the document modification date (excl.time)
//as a string
DateTimeStr = document.lastModified;
secOffset = Date.parse(DateTimeStr);
if (secOffset == 0 || secOffset == null) //Opera3.2
dateStr = &quot;Unknown&quot;;
else
{
aDate = new Date();
aDate.setTime(secOffset);
//use method defined above
datestr = aDate.getLongDateString();
}
return dateStr;
}
// -->
</script>


then put this code where you want the date to be diplayed:


<script language=&quot;JavaScript&quot;>
//<!--
document.write(&quot;<center> Last Update: &quot;);
document.writeln(DocDate(),&quot;</center>&quot;);
// -->
</script>

i don't know much about asp but maybe this will work.

- milech
 
If you have ASP at your disposal why not use it? The javascript version won't work if it's disabled but ASP will always work.
Code:
This page was last updated on 
<% = Request.ServerVariables(&quot;LAST_MODIFIED&quot;) %>
Then you can use
Code:
FormatDateTime()
to format it the way you want it.

You could also use SSI to pull the last modified date out, another way that doesn't depend on Javascript.

Just my two cents...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top