Forum Moderators: open
Sure. You can create a Date object and extract the day, month, and year. These could be used to set the href of a link to a unique page for each day or to a single page but with a set of parameters used to build the page.
The openRecipe() function handles opens a uniquely named page for each date, the altername openRecipe2() function opens a single page but with different parameters for each date. The former approach would require that you have a separate html file for each date (and would of course require you to keep ahead of the current date to prevent the user from getting a 404 not found error).
The latter (openRecipe2) approach would require some kind of server-side scripting or xml/xslt to dynamically build the recipe page with a different recipe each day Although this approach requires some access to server-side scripting, it is definitely a better way to go from a maintenence standpoint.
<script type="text/javascript">
<!--
//get current date from client's system clock
var curDate=new Date()
//get day of the month, month of the year, and year from curDate
var DD=curDate.getDate()
//need to add 1 to getMonth() result because it used zero based notation (January=0)
var MM=curDate.getMonth()+1
var YY=curDate.getFullYear()
//this function handles clicks of the link, sending user to uniquely named link for each day
function openRecipe2(){
//build URL
var recipeURL='recipe_'+DD+'_'+MM+'_'+YY
//open window
window.open(recipeURL,'RecipeWindow')
}
//this alternate function handles clicks of the link, sending user to one page but with parameters
function openRecipe(){
//build URL with one page but different parameters
var recipeURL='recipe.htm?day='+DD+'&month='+MM+'&year='+YY
//open window
window.open(recipeURL,'RecipeWindow')
}
//-->
</script>
</head>
<body>
<p>Click the link below to see today's recipe:</p>
<p><a href="javascript:void(0)" onclick="openRecipe()">Today's Recipe</a></p>
</body>
Hope this helps,
ajkimoto