Javascript-ing to "This Day in History" on wikipedia

Alec Jacobson

September 07, 2009

weblog/

I made a page a while back that redirects to today's date's page on wikipedia. Here's the javascript to build the correct wiki link for the current date.
<script type="text/javascript">
<!--
var months=new Array(12);
months[0]="January";
months[1]="February";
months[2]="March";
months[3]="April";
months[4]="May";
months[5]="June";
months[6]="July";
months[7]="August";
months[8]="September";
months[9]="October";
months[10]="November";
months[11]="December";
function todayWikiLink(){
  var currentTime = new Date();
  var month = months[currentTime.getMonth()];
  var day = currentTime.getDate();
  return 'http://en.wikipedia.org/wiki/'+month+'_'+day+'#Events';
}
//-->
</script>
Originally I just had something like
< body onload="window.location = todayWikiLink();">
But here's a way to have a live link on a page to today's events:
<a onClick="window.open('todayWikiLink()');return false">Today's Historical Events</a>
The URL is generated on the fly so even if the date changes after the page was loaded the link will be correct: Today's Historical Events