I am trying to get the last date that a remote url was updated using javascript. I have currently come up with this:
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);}
}
However, this code seems to always change ‘outUpdate’ to “undefined”. The code is supposed to load the url contents into a frame and then use the document.lastModified function to get the last modified date.
Any ideas on how to fix this?
Thanks!
Josh
You are accessing the element
oIFRAME&oSpanbefore adding them to your document, you have to add these 2 lines before thetryblock:The id of your
iFrameis oIFRAME and not oIFrame, replace this line:By
documentis not a property of youriFrameobject,contentDocumentis. Replace this lineby