View Full Version : Auto redirect based on set time
slider2nl
06-18-2014, 05:02 AM
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..
jscheuer1
06-18-2014, 02:46 PM
Here's a simple script for that:
<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.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.