Teiko1985 Posted March 23, 2012 Share Posted March 23, 2012 Can anyone help me with a 60 second timer for my website. I want to display the following text to my customers at the top of the page: "You will be automatically redirected to homepage in [timer]" In my header I have the following code: <meta http-equiv="refresh" content="61;url=home.php"> Quote Link to comment https://forums.phpfreaks.com/topic/259568-60-timer-needed/ Share on other sites More sharing options...
jcbones Posted March 23, 2012 Share Posted March 23, 2012 No one wants to wait 60 seconds for a page refresh. Most people don't even view a single web page for 60 seconds. But, if you want one, here is a javascript one. <div style="display:none;" id="strclock">Clock Here!</div> <div id="clock">To Update Click the button below!</div> <script type="text/javascript"> var hour = 0; var min = 1; var sec = 0; function checkTime() { var time = document.getElementById('strclock').innerHTML; if(time == '00:00:00') { window.location = 'http://google.com'; } } function countdown() { if(sec <= 0 && min > 0) { sec = 59; min -= 1; } else if(min <= 0 && sec <= 0) { min = 0; sec = 0; } else { sec -= 1; } if(min <= 0 && hour > 0) { min = 59; hour -= 1; } var pat = /^[0-9]{1}$/; secs = (pat.test(sec) == true) ? '0'+sec : sec; mins = (pat.test(min) == true) ? '0'+min : min; hours = (pat.test(hour) == true) ? '0'+hour : hour; document.getElementById('strclock').innerHTML = hours+":"+mins+":"+secs; if(min >= 1) { document.getElementById('clock').innerHTML = min+1+' minutes until timer runs out!'; } else { document.getElementById('clock').innerHTML = sec+' seconds until timer runs out!'; } checkTime(); setTimeout("countdown()",1000); } countdown(); </script> Quote Link to comment https://forums.phpfreaks.com/topic/259568-60-timer-needed/#findComment-1330522 Share on other sites More sharing options...
Teiko1985 Posted March 23, 2012 Author Share Posted March 23, 2012 take a look at my site: mysexywear.com its only because some people based on the lap top screen cannot see my enter site button under my slider so I am in the process of moving everything up but as a safety I redirect them automatically to my homepage. Thanks for the code. I will try it out now! How do I keep the timer in line without dropping down to a second row with the div Quote Link to comment https://forums.phpfreaks.com/topic/259568-60-timer-needed/#findComment-1330523 Share on other sites More sharing options...
Teiko1985 Posted March 23, 2012 Author Share Posted March 23, 2012 The code doesn't work? Quote Link to comment https://forums.phpfreaks.com/topic/259568-60-timer-needed/#findComment-1330527 Share on other sites More sharing options...
jcbones Posted March 24, 2012 Share Posted March 24, 2012 That is funny! That code was tested in the major browsers before being given to you. That being the fact, "doesn't work" doesn't mean anything around here, without specifics and a little code. Quote Link to comment https://forums.phpfreaks.com/topic/259568-60-timer-needed/#findComment-1330629 Share on other sites More sharing options...
trq Posted March 24, 2012 Share Posted March 24, 2012 Firstly: Your question is in NO WAY related to PHP. So it's in the wrong forum. Secondly: We are not here to write code for people. Thirdly: Statements like "code doesn't work" don't help us help you. I'm not sure your ready for this place. Quote Link to comment https://forums.phpfreaks.com/topic/259568-60-timer-needed/#findComment-1330647 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.