Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    Regular Coder
    Join Date
    Nov 2003
    Location
    Vancouver Island Canada
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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>
    Last edited by glenmac; 03-21-2004 at 06:43 PM.


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •