...

View Full Version : Change links Based on Time



glenmac
03-21-2004, 05:38 PM
Hi hope this is useful it changes a link based on the day and time.
<html>
<head>
<script type="text/javascript">
<!--
var startDay = 4; // Start Day: 0 - 6 (Sun = 0, Mon = 1 ... Fri = 5, Sat = 6)
var startHour = 13; // Start Hour: 0 - 23
var startMin = 30; // Start Min: 0 - 59
var endDay = 0; // End Day: 0 - 6 (Sun = 0, Mon = 1 ... Fri = 5, Sat = 6)
var endHour = 8; // End Hour: 0 - 23
var endMin = 0; // End Min: 0 - 59

function alternateLink(linkObj)
{
var startTimeDate = new Date(2004, 01, 01, startHour, startMin, 00);
with (startTimeDate) while (getDay() != startDay) setDate(getDate()+1);
var startTimeDateMsecs = startTimeDate.getTime();

var endTimeDate = new Date(2004, 01, 01, endHour, endMin-1, 00);
with (endTimeDate) while (getDate() < startTimeDate.getDate()) setDate(getDate()+1);
with (endTimeDate) while (getDay() != endDay) setDate(getDate()+1);
var endTimeDateMsecs = endTimeDate.getTime();

var now = new Date();
var currentTimeDate = new Date(2004, 01, 01, now.getHours(), now.getMinutes(), 00);
with (currentTimeDate) while (getDate() < startTimeDate.getDate()) setDate(getDate()+1);
with (currentTimeDate) while (getDay() != now.getDay()) setDate(getDate()+1);
var currentTimeDateMsecs = currentTimeDate.getTime();

if (currentTimeDateMsecs >= startTimeDateMsecs && currentTimeDateMsecs <= endTimeDateMsecs) linkObj.href = 'http://lantzvillecomputers.ca/';
}
//-->
</script>
</head>
<body>
<a href="http://www.yahoo.co.uk/" onclick="alternateLink(this);">Visit Yahoo if time is right if not go to my site</a>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum