Hey all... I've still been working at my website (heh), and I've added in what I think is a nice feature: using XMLHttpRequest to highlight items that were recently modified. Best part is, since I'm only querying my own server, there aren't any associated security issues.
http://www.rpi.edu/~laporj2/index.html is the normal page that you're all used to. (the cookies still have a bug in Opera, trying to figure that one out)
http://www.rpi.edu/~laporj2/index.html?recent is the new page, that automatically highlights all recent (past two weeks) items.
I think it's pretty cool, and a great way to navigate the vast amount of stuff I have on my website (that will only continue to grow, I promise ).
Some fixes that I plan on doing:
- Figure out why it breaks in Opera. Looks like it half-works.
- Cache all the XMLHttpRequests in a session cookie. It's like, 50+ server HEAD queries made on every load of the page. Ick! Once is acceptable, and then they'll all be cached for quick subsequent access.
- Make the recency variable. For example, place a ?5 to see the last five days, or a ?31 to see the last month, or ?365 to see everything added in the previous year. Currently, it's hardwired to be at 14 days.
- Display an unintrusive error message for browsers that don't support XMLHttpRequest.
Maybe that can inspire you all a little. The biggest code change is below:
code:
function lastModifiedDate (anchor) {
var request;
if(window.XMLHttpRequest) request = new XMLHttpRequest();
else if(window.ActiveXObject) request = new ActiveXObject("Microsoft.XMLHTTP");
if(request) {
request.onreadystatechange = function () {
if(request.readyState == 4) {
var date = new Date() - new Date(request.getResponseHeader("last-modified")),
recent = date < threshold;
if(recent)
anchor.className = "recent";
}
}
request.open("HEAD", anchor.href, true);
request.send(null);
}
}
---
Website
(Edited by Iron Wallaby on 05-06-2005 20:29)