...

View Full Version : timer



project5
03-16-2012, 07:07 PM
How could I lock an "Enter" link on an intro page with a 30 second timer that is displayed on the bottom of the page and disables the "Enter" link so that visitors have to wait 30 seconds to read the rules/announcements before entering?

Philip M
03-16-2012, 08:29 PM
How could I lock an "Enter" link on an intro page with a 30 second timer that is displayed on the bottom of the page and disables the "Enter" link so that visitors have to wait 30 seconds to read the rules/announcements before entering?


<body onload = "setTimeout(delayIt, 30000)">

<div id = "mydiv" style="display:none">
<a href = "http://www.google.com">Link to Google</a>
</div>

<script type = "text/javascript">
function delayIt() {
document.getElementById("mydiv").style.display="block";
}

</script>

But people may not be willing to wait that long (especially after the first time) and may simply move on to another site.

If you actually want to show the seconds counting down, use this:-



<body onload = "startTimer(30)">

<span id="countdown" style="font-weight: bold;">30</span>

<div id = "mydiv" style="display:none">
<a href = "http://www.google.com">Link to Google</a>
</div>

<script type = "text/javascript">

var timeInSecs;
var ticker;

function startTimer(secs){
timeInSecs = parseInt(secs);
ticker = setInterval("tick()",1000);
tick(); // get the display started right away

}

function tick() {
var secs = timeInSecs;
if (secs>0) {
timeInSecs--;
}
else {
clearInterval(ticker); // stop counting at zero
document.getElementById("mydiv").style.display="block";
}

document.getElementById("countdown").innerHTML = secs + " seconds to wait";
}

</script>

"A psychiatrist asks a lot of expensive questions that your wife asks for nothing." – Joey Adams

webdev1958
03-17-2012, 12:04 AM
How could I lock an "Enter" link on an intro page with a 30 second timer that is displayed on the bottom of the page and disables the "Enter" link so that visitors have to wait 30 seconds to read the rules/announcements before entering?

You can't actually force people to read anything on a web page. But what you can do is get them to say they have read something whether they have or haven't.

I wouldn't show a count down timer because I think that would be too distracting for most people while they are trying to read what you really want them to see. If you have a timer display, most will just watch it count down.

Another option is to use a checkbox that the user must tick to enable the Enter button. The check box would just need an onclick event handler that calls enableEnter() if the checkbox is checked.


<body>
<div>Rules and Announcements</div>
<div><button id="btnEnter">Enter</button></div>
<script type="text/javascript">
var btnEnterO = document.getElementById('btnEnter');
btnEnterO.disabled = true;
function enableEnter(){
btnEnterO.onclick=function(){
window.location.href='url1';
}
btnEnterO.disabled = false;
}
setTimeout(enableEnter,5000);
</script>
</body>With a javascript only solution it is too easy to bypass the timer and so in the real world I would use a server side solution.

Philip M
03-17-2012, 08:52 AM
With a javascript only solution it is too easy to bypass the timer and so in the real world I would use a server side solution.

If the user is confirming that he accepts the terms and conditions of your site, then it is essential that this is also validated server-side.

webdev1958
03-17-2012, 09:53 AM
If the user is confirming that he accepts the terms and conditions of your site, then it is essential that this is also validated server-side.

yep :thumbsup:. Validating user inputs is part of normal "good practice" server side processing. I think you'll find that validating user inputs server side is a "must do" has been mentioned ad infinitum all over the place and it doesn't do any harm to mention it again :)

Philip M
03-17-2012, 10:10 AM
yep :thumbsup:. Validating user inputs is part of normal "good practice" server side processing. I think you'll find that validating user inputs server side is a "must do" has been mentioned ad infinitum all over the place and it doesn't do any harm to mention it again :)

And it gives you yet another opportunity to increase your post count!

webdev1958
03-17-2012, 10:17 AM
And it gives you yet another opportunity to increase your post count!

What's the deal with post count? Is there a prize after reaching a target? I doubt it.

Post count to me means nothing. I look at what people say, not how many times they have said something. Someone could make their first post on one website while having 20,000 posts on another website :)

So it's a case of - yeah whatever :) :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum