我想要使用JavaScript更新远程URL的最后日期。我目前想出了这个:使用javascript获取远程URL的最后修改日期
function getlastmod(url)
{
var ifrm = document.createElement("IFRAME");
ifrm.setAttribute("src", url);
ifrm.setAttribute("id", "oIFRAME");
ifrm.style.display = "none";
var spanTag = document.createElement("span");
spanTag.id = "oSpan";
try
{
var oIFrame = document.getElementById("oIFrame");
var oSpan = document.getElementById("oSpan");
oSpan.innerHTML = oIFrame.src + " last modified " +
oIFrame.document.lastModified;
outUpdate=oSpan;
}
catch(E) {setTimeout("getlastmod();",50);}
}
但是,这段代码似乎总是将'outUpdate'更改为“undefined”。代码应该将url内容加载到一个框架中,然后使用document.lastModified函数获取最后修改的日期。
有关如何解决此问题的任何想法?
谢谢! Josh
outUpdate是什么变量?它是全球性的还是你打算通过这个功能返回它? – 2012-07-21 13:32:53
@GrzegorzKaczan它是一个全局变量,稍后会用到。 – Josh 2012-07-21 13:38:01