views:

106

answers:

4

I have a set of links on a web page that link to PDF forms and .doc forms. These files are not stored in a database, simply stored as they are, locally on the server. Is it possible to retrieve the last modified date of a PDF or DOC file using Javascript? I don't have any specific need to use Javascript, but it is preferable.

UPDATE: Now that I realize that Javascript can't access the filesystem, is there an alternative method?

+1  A: 

No, it's not. You can't access the file system through JavaScript

Naeem Sarfraz
But you can send an AJAX request to a server-side process to get the info you need within JavaScript.
Daniel Straight
Good point, yes you can
Naeem Sarfraz
A: 

No. For the security reasons.

P.S.: As far as I remember, long time ago it was possible on IE with ActiveX, but it was a big area for viruses and deprecated.

vas3k
A: 

If an interface is exposed through HTTP, you can. Another way of saying: expose a WebService end-point to gain access to this information.

Of course, you can't have direct access to the filesystem for security reasons.

jldupont
+2  A: 

If it's on the same server as your calling function you can use XMLHttpRequest-

this example is not asynchronous, but you can make it so if you wish.

function fetchHeader(url, wch){
 try{
  var req=new XMLHttpRequest();
  req.open("HEAD", url, false);
  req.send(null);
  if(req.status== 200){
   return req.getResponseHeader(wch);
  }
  else return false;
 }
 catch(er){
  return er.message
 }
}

alert(fetchHeader(location.href,'Last-Modified'))

kennebec