Go Back   HTMLCenter Web Development Forums > Web Design and Development > Programming and Scripting
Connect with Facebook

Using JS document.lastModified function

Closed Thread
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 06-03-2009, 01:46 PM
Registered User
 
Join Date: Jun 2009
Posts: 3
Using JS document.lastModified function

Hello,

I am not a programmer, and I'm trying to use any of several JS scripts I've found on the net to display an HTML file's last-modified date in a Mac environment (Unix servers). The first script (see script 1 below) seems to display the current system date, rather than the file's last-modified date. The other two scripts (see scripts 2 and 3 below) produce a blank line in both Safari and Firefox.

I've tried both embedding the JS in the HTML file and referencing it from an external file. There's no difference in the results. I'd prefer to reference an external JS file, so I can easily affect multiple pages in the small site I'm creating (4 pages).

The calling code is shown below:

Code:
<div id="footer">
<p><script type="text/JavaScript" src="../savedate.js"></script>
<noscript>
  Updated June, 2008
</noscript>

<br>
	Comments and corrections: <a href="[email_alias_here]?subject=Comment or correction on workflow page titled: ">contact the webmaster</a></p>
	<!-- Footer end -->
	</div>
Is it possible that the server does not have the module that supports the methods that the JS is using?
------------------------------

Script 1: appears to display current date

Code:
<!--
// Y2K READY-USE GetFullYear
// DAY Names Javascript is funny Starts the numbering with Zero this array translates to 0...6 to the days of the week
// REMEMBER Arrays have to be written all on ONE(1) line to work
var stampdays = new Array( "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
// Month Names - Guess what this array does. 0..11 to the system clock month
var stampmonths = new Array( "January","February","March","April","May","June","July","August","September","October","November","December");
// GRABS the Date info from your System clock when your Browser reads enters the page.
var thedate = new Date();
//Gets the Translated Arrays written to the webpage for viewing. Remember you can use this for other things, too
document.write(stampdays[ thedate.getDay()] + ", " + stampmonths[ thedate.getMonth()] + " " + thedate.getDate() + ", " + thedate.getFullYear());
// -->
---------------
Script 2: produces blank line

Code:
<!-- Hide from old browsers
//
// format date as dd-mmm-yy
// example: 12-Jan-99
//
function date_ddmmmyy(date)
{
  var d = date.getDate();
  var m = date.getMonth() + 1;
  var y = date.getYear();

  // handle different year values 
  // returned by IE and NS in 
  // the year 2000.
  if(y >= 2000)
  {
    y -= 2000;
  }
  if(y >= 100)
  {
    y -= 100;
  }

  // could use splitString() here 
  // but the following method is 
  // more compatible
  var mmm = 
    ( 1==m)?'Jan':( 2==m)?'Feb':(3==m)?'Mar':
    ( 4==m)?'Apr':( 5==m)?'May':(6==m)?'Jun':
    ( 7==m)?'Jul':( 8==m)?'Aug':(9==m)?'Sep':
    (10==m)?'Oct':(11==m)?'Nov':'Dec';

  return "" +
    (d<10?"0"+d:d) + "-" +
    mmm + "-" +
    (y<10?"0"+y:y);
}


//
// get last modified date of the 
// current document.
//
function date_lastmodified()
{
  var lmd = document.lastModified;
  var s   = "Unknown";
  var d1;

  // check if we have a valid date
  // before proceeding
  if(0 != (d1=Date.parse(lmd)))
  {
    s = "" + date_ddmmmyy(new Date(d1));
  }

  return s;
}

//
// finally display the last modified date
// as DD-MMM-YY
//
document.write( 
  "Last updated: " + 
  date_lastmodified() );

// -->
------------------
Script 3: produces blank line

Code:
<!--
lastmod = document.lastModified     // get string of last modified date
lastmoddate = Date.parse(lastmod)   // convert modified string to date
if (lastmoddate == 0) {               // unknown date (or January 1, 1970 GMT)
  document.writeln("Last Modified: Unknown")
  } else {
    document.writeln("Last Modified: " + lastmod)
    }
// -->

Last edited by axcohn; 06-03-2009 at 05:45 PM..

  #2 (permalink)  
Old 06-03-2009, 08:20 PM
curtiss's Avatar
Moderator
 
Join Date: May 2003
Posts: 1,533
Quote:
Originally Posted by axcohn View Post
Is it possible that the server does not have the module that supports the methods that the JS is using?
Not very likely. It would be more likely that Safari and Firefox don't support the lastModified propery, but I doubt that, too.

I would suspect the most likely culprit is probably a minor error in the javascript code. Please use the javascript console in Firefox to examine the page for any errors or warnings that are being generated.
__________________
I hate Internet Explorer! Anyone with me?
  #3 (permalink)  
Old 06-04-2009, 03:36 PM
Registered User
 
Join Date: Jun 2009
Posts: 3
Works with FF, not Safari

Just because I had no other ideas, I looked again at my test page in both FF and Safari. Today, the JS works as expected in FF, but not Safari. I viewed both the FF error console and Firebug, and neither reported an error. There is, apparently, something special required for Safari to process the JS — I just don't know what.
  #4 (permalink)  
Old 06-05-2009, 11:46 AM
Registered User
 
Join Date: Jun 2009
Posts: 3
The root problem is SSI configuration

I've finally come to understand (thanks, Rob Weaver) that the root problems are these:
  • I should be using server-side includes; JS just deals with client-side information (unless the server has a compiler for executing JS on the server)
  • I'm not sure whether the corporate web servers are configured to enable SSIs for the directory where the microsite is hosted.
I've contacted my server support group about this, giving them some very specific questions about the configuration of their mod_include module.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
My Java script function is not getting called from my form and do not know why ? fshaw Programming and Scripting 4 03-17-2009 07:59 AM
include files or function in a for loop possible? gilgalbiblewhee Programming and Scripting 2 09-25-2008 10:01 PM
Jump to a sub Function from a link???? NevadaSam Programming and Scripting 2 05-08-2006 10:37 AM
showLayer function, layer position problem ruthann Programming and Scripting 3 03-19-2006 10:13 AM
How do I highlight a split function text? gilgalbiblewhee Programming and Scripting 7 01-31-2006 04:12 PM


All times are GMT -5. The time now is 05:28 AM.

 
Clicky Web Analytics
CloudContacts
Loop11
Page.ly


Subscribe to our feed | add to myYahoo!

Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.5.1 PL1
© 1997-2009 HTMLCenter