PDA

View Full Version : Problems working with Time-Dependent Scripts - Please Help


wipeout
09-23-2002, 04:09 PM
Searched desperately for a script that redirects visitor to a page depending on time of day. The closest I could find was this one for swapping images. Is there a way to modify fo create the desired effect?

var current= new Date()
var day_night=current.getHours()
if (day_night<=12)
document.write("<img src='day.gif'>")
else
document.write("<img src='night.gif'>")

:confused:

beetle
09-23-2002, 04:29 PM
If all you need is the the two separations, (am/pm) then this script will work finevar current= new Date()
var day_night=current.getHours()
if (day_night<=12)
location.href="morning_page.htm";
else
location.href="evening_page.htm"; But, with just these two conditions, this is a great opportunity for a ternary statementvar current= new Date()
var day_night=current.getHours()
location.href = (day_night<=12) ? "morning_page.htm" : "evening_page.htm";