I have looked high and low for a very simple script that i can use to display on a page from 6 down to 1.

Basically it should start like this:

"this page will redirect in 6 seconds"

and end like this:

"this page will redirect in 0 seconds"

I know exactly the type of people on this forum and how clever you are so if you could please just help me out, I will be really really grateful.

Thanks

Recommended Answers

All 2 Replies

Normally such a thing is almost always done using a server side script (you know why), but since you have been nice in your conduct on Daniweb, I would try something out for you. :)

How about something like:

<!--
author: Sanjay aka ~s.o.s~ 
A simple redirection script which runs on the client side.
-->
<html>
<head>
<style>
 .myDiv
 {
  text-align: center;
  font: italic small-caps 900 14px arial
 }
</style>
<script>
 var count = 5;
 var timerHandle;
 var URL = "[URL]http://www.yahoo.com[/URL]";
 var SITE_NAME = "Yahoo";
 
 function startCountDown()
 {
  update();
  timerHandle = setInterval("update()", 1000);
 }
 
 function update()
 {
  if(count <= 0)
  {
   clearInterval(timerHandle);
   document.getElementById('txt').innerHTML = 'Redirecting, please wait...';
   window.location.assign(URL);
   /*
   You can also use the window.location.replace() function with the difference
   being you won't be able to hit the back button once the new page has been
   loaded. Use the function which suits your purpose
   */
  }
  else
  {
   //you can also embed the entire message in a 'anchor' tag so that the user can decide not to
   //wait and click on the link to go to the site.
   document.getElementById('txt').innerHTML = 'You would be redirected to '+ SITE_NAME + ' in ' + count + ' seconds.';
   --count;
  }
 }
 
</script>
</head>
<body onload="javascript:startCountDown();">
<br /><br /><br />
<div class="myDiv" id="txt"></div>
</body>
</html>

Just let me know if it works for your cause. ;-)

:icon_redface: Really sorry to put your through that. I actually dont thank you for it and I am sure other will find it useful.

I have done the redirect in php.

All I wanted to know was how to just simply count from 6 down to 1 in javascript. It really is probably a 2 line code.

Thanks for your help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.