Created
December 31, 2011 00:38
-
-
Save saranrapjs/1542232 to your computer and use it in GitHub Desktop.
Detect last-modified HTTP headers (via ajax) and use them
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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