[WEB4LIB] date last modified script?
TMGB
bennettt at am.appstate.edu
Wed Feb 9 13:31:36 EST 2000
I recall, I think from this list, a y2k problem with the date function
[probably getDate() which this doesn't use] but this works on my web
server (Alpha NT running Netscape Enterprise Server). I've used it so
long that I'm not sure if I am remembering this properly but the main
thing here is that this script reads the date of the file from its
time/date stamp and sets a cookie on the user's browser. If the date on
the cookie is older than the date of the file then (in red) it states
that this page has changed since the user last visited. I commented out
this line because I've had a problem with document.write() where the
text inside the parens and " " has a ' or " . This is because I now have
all of our pages calling the javascript rather than relying on everyone
correctly putting the script in their web page. This also allows me to
make changes globally by editing one file. When you look at the source
code for the page you see javascript calls that look like this :
Call to menu box
<script language="JavaScript" src="/javascript/clik5.js"></script>
Call to button bar for bottom of page
<script language="JavaScript" src="/javascript/bbar.js"></script>
Call to page update js (included here)
<script language="JavaScript" src="/javascript/pageupdate.js"></script>
This is what appears in the browser for
http://www.library.appstate.edu/Distance_Learning/ :
This page last updated on:
Monday, November 08, 1999 12:29:20
If you copy this script directly to an html file then you may want to
uncomment (remove //) in front of document.write('This page has changed
... ) and replace it with a carriage return so it can be read more
easily. If you have the same problem I do with ' and " and find a
solution I would appreciate being made aware of the fix.
Thomas
<!-- This Script And Over 400 Others Found At --!>
<!-- Java City 2000 http://www.jc2k.com --!>
<!----- Script CopyRight © 1996 - 1997 S.Chris Brown (Spikeman)
http://www.geocities.com/BourbonStreet/3843
/*******************************************************
** S.Christopher Brown's (Spikeman)'s **
** java script Cookie (lastModified ) **
** CopyRight © 1996 - 1997 S.Chris Brown (Spikeman) **
** http://www.geocities.com/BourbonStreet/3843 **
** All Rights Reserved **
** You can freely use this script, if this credit is **
** given in the source. So that mean don't mess around **
** with my ( Spikeman ) Script or Script's k ? **
** Thank you **
*********************************************************/
document.write("<br><font size=-2>")
// This JavaScript code Modifications by S.Chris Brown (Spikeman) 1996
- 1997 ( http://www.geocities.com/BourbonStreet/3843 )
<!-- hide from non-JavaScript browsers
function getCookieVal (offset) {
var endstr = document.cookie.indexOf ("Update_Cookie", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf("Update_Cookie", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
function DeleteCookie(name) {
var exp = new Date();
FixCookieDate (exp); // Correct for Mac bug
exp.setTime (exp.getTime() - 1); // This cookie is history
var cval = GetCookie (name);
if (cval != null)
document.cookie = name + "=" + cval + "; expires=" +
exp.toGMTString();
}
var cookie_date=new Date(document.lastModified);
var expdate = new Date();
expdate.setTime(expdate.getTime()+(1*5*18*33*1000));
document.write("This page last updated on:<br> "+document.lastModified);
// document.write("<br>");
if (!(cookie_date == GetCookie("cookie_date"))){
SetCookie("cookie_date",cookie_date,expdate);
document.write("<!-- updated -->"); //document.write("<font
color='Red'>This page has changed since your last visit!</font><br>");
}
document.write("</font>")
// end hide -->
"Mariner, Vincent A." wrote:
>
> Hello folks,
>
> Can anyone point me to a date last modified script? The one I currently
> use is not working correctly in Netscape Communicator.
>
> Here's the current scipt:
>
> <SCRIPT TYPE="text/javascript"> var theDate = ""
> theDate = document.lastModified
> document.writeln("Last Updated: ");
> document.write(theDate);
> document.write();
> </SCRIPT>
>
> and here is what it produces in Netscape Communicator:
>
> Last Updated: Wednesday, December 31, 1969 20:00:00
>
> Works just fine in I.E. 5
>
> As I looked for a script, I noticed that many people are not using scripts
> for this purpose. Is this more appropriate, common, a trend, etc.?
>
> Thanks,
> Vince
--
--------------------------------------------------------------------
Rock and Rule
Zope Rocks -- http://www.zope.org
Python Rules -- http://www.python.org
--------------------------------------------------------------------
Thomas McMillan Grant Bennett Appalachian State University
Computer Consultant II University Library
bennettt at am.appstate.edu
http://www.library.appstate.edu/webmaster/
Voice: 828 262 6587 FAX: 828 262 3001
Windows 95 is a 32-bit extension to a 16-bit patch for an 8-bit
operating system that was originally coded for a 4-bit microprocessor.
- Chris Dunphy Boot Magazine
More information about the Web4lib
mailing list