Enjoy an ad free experience by logging in. Not a member yet?
Register .
08-22-2011, 11:34 AM
PM User |
#1
New Coder
Join Date: Dec 2010
Location: UK
Posts: 67
Thanks: 15
Thanked 0 Times in 0 Posts
Countdown to page refresh
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...
Quote:
<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
08-22-2011, 11:47 AM
PM User |
#2
Senior Coder
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
Put this code into the <body>
Code:
<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>
Users who have thanked devnull69 for this post:
08-22-2011, 12:30 PM
PM User |
#3
Supreme Master coder!
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Code:
<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.
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Last edited by Philip M; 08-22-2011 at 12:48 PM ..
Users who have thanked Philip M for this post:
08-22-2011, 12:45 PM
PM User |
#4
Senior Coder
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
@Philip_M He already has the page refresh in his META tag ... but nevertheless, your code will work fine, too
08-22-2011, 12:47 PM
PM User |
#5
Supreme Master coder!
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Quote:
Originally Posted by
devnull69
@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.
And I left the <div> out.
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
08-22-2011, 12:51 PM
PM User |
#6
Banned
Join Date: Apr 2011
Posts: 656
Thanks: 14
Thanked 69 Times in 69 Posts
Quote:
Originally Posted by
Philip M
Oh, sorry, I did not notice the META tag.
And I left the <div> out.
In case you don't know what the meta tag does,
this explanation might help.
08-22-2011, 01:12 PM
PM User |
#7
New Coder
Join Date: Dec 2010
Location: UK
Posts: 67
Thanks: 15
Thanked 0 Times in 0 Posts
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
08-22-2011, 01:26 PM
PM User |
#8
Senior Coder
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
Philip's code added the refresh part to Javascript, so you could as well use his code and remove the META tag
08-22-2011, 01:27 PM
PM User |
#9
New Coder
Join Date: Dec 2010
Location: UK
Posts: 67
Thanks: 15
Thanked 0 Times in 0 Posts
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
08-22-2011, 01:28 PM
PM User |
#10
Senior Coder
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
You can use any string that produces valid HTML ...
08-22-2011, 01:32 PM
PM User |
#11
New Coder
Join Date: Dec 2010
Location: UK
Posts: 67
Thanks: 15
Thanked 0 Times in 0 Posts
I knew it was a stupid question! Thanks for your help
08-22-2011, 01:47 PM
PM User |
#12
New Coder
Join Date: Dec 2010
Location: UK
Posts: 67
Thanks: 15
Thanked 0 Times in 0 Posts
oh wait sorry! Just tryed to include a link with no luck... I think it dislikes the <a> tags and "
Quote:
if you are not redirected <a href="http://site.com">please click here </a>
08-22-2011, 01:51 PM
PM User |
#13
Senior Coder
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
Because
Code:
"<a href="linkpage.html">"
is not a valid string, whereas
Code:
"<a href=\"linkpage.html\">"
or
Code:
'<a href="linkpage.html">'
is
Users who have thanked devnull69 for this post:
08-22-2011, 02:00 PM
PM User |
#14
New Coder
Join Date: Dec 2010
Location: UK
Posts: 67
Thanks: 15
Thanked 0 Times in 0 Posts
SUCCESS! Thanks mate!
Jump To Top of Thread
Thread Tools
Rate This Thread
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
All times are GMT +1. The time now is 10:07 PM .
Advertisement
Log in to turn off these ads.