...

View Full Version : Countdown to page refresh



designedbyria
08-22-2011, 11:34 AM
Hi Guys,

Our company own a lot of domains and want to put a short page of copy on each address along with keywords before redirecting the user to our main site.

I have been able to get the page to load the main site after the desired time using this code in the head...


<META HTTP-EQUIV="refresh" CONTENT="40;URL=http://webaddress.com/">


That works perfectly, I am now trying to display a countdown timer from 40 seconds down to 0, and on 0 redirect the user. Saying something like "You will be redirected in XX seconds".

Is there anyway of doing this? I've been searching google for the answers with no luck and can only seem to find timers that countdown to a set date.

Thanks in advance!
Ria

devnull69
08-22-2011, 11:47 AM
Put this code into the <body>


<div id="countdown"></div>
<script type="text/javascript">
var duration = 40;
showDuration();

function showDuration() {
document.getElementById('countdown').innerHTML = "You will be redirected in " + duration + " seconds";
duration--;
window.setTimeout(showDuration, 1000);
}

</script>

Philip M
08-22-2011, 12:30 PM
<div id="countdown"></div>

<script type="text/javascript">

var duration = 40;
showDuration();

function showDuration() {
document.getElementById('countdown').innerHTML = "You will be redirected in " + duration + " seconds";
duration--;
if (duration >=0) {
window.setTimeout(showDuration, 1000);
}
else {
window.location.href = "http://www.google.com";
}
}

</script>


Quizmaster: What is the name of the river that runs through Rome?
Contestant: The Nile.

devnull69
08-22-2011, 12:45 PM
@Philip_M He already has the page refresh in his META tag ... but nevertheless, your code will work fine, too

Philip M
08-22-2011, 12:47 PM
@Philip_M He already has the page refresh in his META tag ... but nevertheless, your code will work fine, too

Oh, sorry, I did not notice the META tag. :eek: And I left the <div> out. :o

webdev1958
08-22-2011, 12:51 PM
Oh, sorry, I did not notice the META tag. :eek: And I left the <div> out. :o

In case you don't know what the meta tag does, this explanation (http://www.metatags.org/meta_http_equiv_refresh) might help.

designedbyria
08-22-2011, 01:12 PM
Excellent! Thanks guys! DevNull69 your code works perfectly and does just what I need it to do! Many thanks, Philip M - I'm not quite sure how yours is different? Thanks all the same :)

devnull69
08-22-2011, 01:26 PM
Philip's code added the refresh part to Javascript, so you could as well use his code and remove the META tag

designedbyria
08-22-2011, 01:27 PM
ok here's another stupid question...

How do I style up the text? I can't use <p> tags can I?

Thanks!

Also it would be able to put a link in there too... "if you are not redirected click here"

Many thanks

devnull69
08-22-2011, 01:28 PM
You can use any string that produces valid HTML ...

designedbyria
08-22-2011, 01:32 PM
I knew it was a stupid question! Thanks for your help

designedbyria
08-22-2011, 01:47 PM
oh wait sorry! Just tryed to include a link with no luck... I think it dislikes the <a> tags and "


if you are not redirected <a href="http://site.com">please click here </a>

devnull69
08-22-2011, 01:51 PM
Because


"<a href="linkpage.html">"

is not a valid string, whereas


"<a href=\"linkpage.html\">"

or


'<a href="linkpage.html">'

is

designedbyria
08-22-2011, 02:00 PM
SUCCESS! Thanks mate!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum