Skip to content

Instantly share code, notes, and snippets.

@saranrapjs
Created December 31, 2011 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saranrapjs/1542232 to your computer and use it in GitHub Desktop.
Save saranrapjs/1542232 to your computer and use it in GitHub Desktop.
Detect last-modified HTTP headers (via ajax) and use them
function updated_when() {
var xmlhttp;
var last_modified = {};
if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
var lm_str = xmlhttp.getResponseHeader('Last-Modified');
if (lm_str != '') {
last_modified.date = new Date(lm_str);
var date_div = document.createElement("div");
date_div.innerHTML = "this page was edited on "+ (last_modified.date.getMonth()+1) + "/" + last_modified.date.getDate();
last_modified.html = date_div;
return last_modified;
}
}
}
xmlhttp.open("GET",location.href,true);
xmlhttp.send();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment