是否可以使用Javascript检索文件的上次修改日期? [英] Is it possible to retrieve the last modified date of a file using Javascript?
问题描述
我在网页上有一组链接,这些链接可以链接到PDF表单和.doc表单.这些文件不存储在数据库中,而是按原样存储在服务器本地.是否可以使用Javascript检索PDF或DOC文件的最后修改日期?我没有使用Javascript的任何特定需求,但这是可取的.
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.
更新:现在,我意识到Javascript无法访问文件系统,是否有替代方法?
UPDATE: Now that I realize that Javascript can't access the filesystem, is there an alternative method?
推荐答案
如果它与调用函数位于同一服务器上,则可以使用XMLHttpRequest-
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'));
这篇关于是否可以使用Javascript检索文件的上次修改日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!