Results 1 to 2 of 2

Thread: Auto redirect based on set time

  1. #1
    Join Date
    Jun 2014
    Location
    Netherlands
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Auto redirect based on set time

    I am looking for a script that can be set to redirect based on fixed time lets say:
    redirect to url when the system clock or server clock hits 18:00,

    Foud something here: http://www.javascriptkit.com/script/script2/alarm.shtml

    But i dont need the dropdown and form elements.. Can someone help to make a simpel script that i can use..

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,070
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    Here's a simple script for that:

    Code:
    <script type="text/javascript">
    setInterval(function(){
    	var t = 18, url = 'http://www.dynamicdrive.com/',
    	now = new Date(), h = now.getHours(), m = now.getMinutes();
    	if(h === t && m < 1){window.location.replace(url);}
    }, 1000);
    </script>
    18 is the target hour (0 - 23) and http://www.dynamicdrive.com/ is the destination address for when the clock strikes the target hour.

    Consider however whether or not you want it to only happen when the clock strikes the target hour or perhaps at the target hour and until another target time. As illustration - In the above code it will (checking every second) continue to redirect for about a minute. So if you got to the page at 18:00:30 - say, it would still redirect you. If you get there at 18:01:00, too late, you stay where you are.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Redirect Based On Date AND Time
    By Zackeriney in forum PHP
    Replies: 8
    Last Post: 10-08-2010, 05:22 PM
  2. Redirect based upon IE6 or IE7
    By Hummell in forum Looking for such a script or service
    Replies: 5
    Last Post: 08-15-2008, 11:16 AM
  3. Redirect Based On Time
    By redtrain in forum PHP
    Replies: 6
    Last Post: 12-22-2006, 04:53 AM
  4. Replies: 2
    Last Post: 10-22-2006, 01:25 PM
  5. Redirect based on url
    By noz in forum JavaScript
    Replies: 4
    Last Post: 08-30-2005, 12:31 PM

Bookmarks

Posting Permissions

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