Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-22-2011, 11:34 AM   PM User | #1
designedbyria
New Coder

 
Join Date: Dec 2010
Location: UK
Posts: 67
Thanks: 15
Thanked 0 Times in 0 Posts
designedbyria is an unknown quantity at this point
Exclamation 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
designedbyria is offline   Reply With Quote
Old 08-22-2011, 11:47 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
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>
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
designedbyria (08-22-2011)
Old 08-22-2011, 12:30 PM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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..
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
designedbyria (08-22-2011)
Old 08-22-2011, 12:45 PM   PM User | #4
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
@Philip_M He already has the page refresh in his META tag ... but nevertheless, your code will work fine, too
devnull69 is offline   Reply With Quote
Old 08-22-2011, 12:47 PM   PM User | #5
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by devnull69 View Post
@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.
Philip M is offline   Reply With Quote
Old 08-22-2011, 12:51 PM   PM User | #6
webdev1958
Banned

 
Join Date: Apr 2011
Posts: 656
Thanks: 14
Thanked 69 Times in 69 Posts
webdev1958 can only hope to improve
Quote:
Originally Posted by Philip M View Post
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.
webdev1958 is offline   Reply With Quote
Old 08-22-2011, 01:12 PM   PM User | #7
designedbyria
New Coder

 
Join Date: Dec 2010
Location: UK
Posts: 67
Thanks: 15
Thanked 0 Times in 0 Posts
designedbyria is an unknown quantity at this point
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
designedbyria is offline   Reply With Quote
Old 08-22-2011, 01:26 PM   PM User | #8
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Philip's code added the refresh part to Javascript, so you could as well use his code and remove the META tag
devnull69 is offline   Reply With Quote
Old 08-22-2011, 01:27 PM   PM User | #9
designedbyria
New Coder

 
Join Date: Dec 2010
Location: UK
Posts: 67
Thanks: 15
Thanked 0 Times in 0 Posts
designedbyria is an unknown quantity at this point
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
designedbyria is offline   Reply With Quote
Old 08-22-2011, 01:28 PM   PM User | #10
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
You can use any string that produces valid HTML ...
devnull69 is offline   Reply With Quote
Old 08-22-2011, 01:32 PM   PM User | #11
designedbyria
New Coder

 
Join Date: Dec 2010
Location: UK
Posts: 67
Thanks: 15
Thanked 0 Times in 0 Posts
designedbyria is an unknown quantity at this point
I knew it was a stupid question! Thanks for your help
designedbyria is offline   Reply With Quote
Old 08-22-2011, 01:47 PM   PM User | #12
designedbyria
New Coder

 
Join Date: Dec 2010
Location: UK
Posts: 67
Thanks: 15
Thanked 0 Times in 0 Posts
designedbyria is an unknown quantity at this point
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>
designedbyria is offline   Reply With Quote
Old 08-22-2011, 01:51 PM   PM User | #13
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Because
Code:
"<a href="linkpage.html">"
is not a valid string, whereas
Code:
"<a href=\"linkpage.html\">"
or
Code:
'<a href="linkpage.html">'
is
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
designedbyria (08-22-2011)
Old 08-22-2011, 02:00 PM   PM User | #14
designedbyria
New Coder

 
Join Date: Dec 2010
Location: UK
Posts: 67
Thanks: 15
Thanked 0 Times in 0 Posts
designedbyria is an unknown quantity at this point
SUCCESS! Thanks mate!
designedbyria is offline   Reply With Quote
Reply

Bookmarks

Tags
countdown, load, refresh, timer

Jump To Top of Thread


Thread Tools
Rate This Thread
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:07 PM.


Advertisement
Log in to turn off these ads.