Go Back   CodingForums.com > :: Client side development > JavaScript programming > Post a JavaScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-21-2004, 05:38 PM   PM User | #1
glenmac
Regular Coder

 
Join Date: Nov 2003
Location: Vancouver Island Canada
Posts: 139
Thanks: 0
Thanked 0 Times in 0 Posts
glenmac is an unknown quantity at this point
Change links Based on Time

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>
__________________
lantzvillecomputers.com

Last edited by glenmac; 03-21-2004 at 05:43 PM..
glenmac is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:30 AM.


Advertisement
Log in to turn off these ads.