Forum Moderators: open

Message Too Old, No Replies

JavaScript For New Page

Looking for Javascript to load a new pages daily...

         

rceph

11:58 pm on Apr 11, 2004 (gmt 0)

10+ Year Member



Hi there!
Is there any javascript to load a new pages daily. I wish to put a daily recipes that can load a new page daily. It is possible?

Rambo Tribble

3:26 am on Apr 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is fairly easy to write a script that will select a file to load and to make it increment by day or visit from an individual, but that would require cookies. It sounds more like you want a server side script, that will serve a different page every day, the same page to every visitor on that day.

ajkimoto

4:38 am on Apr 12, 2004 (gmt 0)

10+ Year Member



rceph,

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

rceph

2:11 pm on Apr 13, 2004 (gmt 0)

10+ Year Member



Ajkimoto- Thank you!