How do I correct this Last Modified script so it works on Safari/Chrome the way it does in IE/Firefox?

In IE and Firefox this script works the way I want it to - showing a date such as 11/08/08.  On Chrome or Safari it just displays "Sun,".  I am not very familiar with JavaScript - what do I need to change to fix this?
<script type="text/javascript">
<!--
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(" " + lastmod.split(" ")[0]);
}// -->
</script>

Open in new window

maeve100Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

quincydudeCommented:
document.lastModified is not a W3C standard so it may not be function in every browser
0
quincydudeCommented:
Hi, I have made a AJAX version that chrome also supports. But your browser must support AJAX (which most of them do)
Hope this helps.

<html>
<head>
 
<script type="text/javascript">
var xmlhttp;
 
function loadXMLDoc(url){
	xmlhttp=null;
	if (window.XMLHttpRequest)
	{// all modern browsers
		xmlhttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{// for IE5, IE6
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (xmlhttp!=null)
	{
		xmlhttp.onreadystatechange=state_Change;
		xmlhttp.open("GET",url,true);
		xmlhttp.send(null);
	}
	else
	{
		alert("Your browser does not support XMLHTTP.");
	}
}
 
function state_Change()
{
if (xmlhttp.readyState==4)
  {// 4 = "loaded"
  if (xmlhttp.status==200)
   {// 200 = "OK"
	
	lastmod = xmlhttp.getResponseHeader('Last-Modified');		 
	lastmoddate = Date.parse(lastmod);   // convert modified string to date
	if ( lastmod == null || lastmod == "" || lastmoddate == 0) {     // unknown date (or January 1, 1970 GMT)
	alert(" Last Modified: Unknown");
	} else {
	alert(" Last Modified:" + lastmod);
	}
 
    }
  else
    {
    alert("Problem retrieving data:" + xmlhttp.statusText);
    }
  }
}
 
 
 
</script>
</head>
<body>
<p id="me"></p>
<button onclick="loadXMLDoc(document.URL);">Get "Last-Modified"</button>
 
</body>
</html>

Open in new window

0
Michel PlungjanIT ExpertCommented:
Wouldn't a HEAD be enough?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Michel PlungjanIT ExpertCommented:
Anyway, judging from your post you get another format than your script expects.

Try this


<script type="text/javascript">
<!--
var lastmod = document.lastModified     // get string of last modified date
document.write(" Last Modified: ")
if (lastmod == 0) {               // unknown date (or January 1, 1970 GMT)
  document.writeln("Unknown")
}
else {
  var lastmoddate = new Date(Date.parse(lastmod));
  var yyyy = lastmoddate.getFullYear();
  var mm = lastmoddate.getMonth()+1;
  var dd = lastmoddate.getDate();
  if (mm<10) mm="0"+mm;
  if (dd<10) dd="0"+dd;
  document.writeln(yyyy +'/'+mm+'/'+dd);
}// -->
</script>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Michel PlungjanIT ExpertCommented:
Interestingly this script does not work on my site in safari
http://plungjan.name/ee/lastmod.html

but does here

http://homepage.mac.com/frank.ia.us/Sites/skl/skl.htm
0
maeve100Author Commented:
Thank you for the help - sorry for the delay, I was having trouble with my server and was unable to test for a few days.  It works fine for me in both Safari and Chrome.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.