Search code examples
phphtmlhttp-redirectrefreshcountdown

Countdown -> Redirect -> Reset


I tried to make a countdown that when finishes redirects to another url (even if i'm not online on page, this page i want to redirect to, does something) then resets countdown.

Here is the countdown:

<HTML>
<HEAD>
<TITLE>Countdown</TITLE>
<SCRIPT LANGUAGE="JavaScript">

var eventdate = new Date("May 19, 2013 21:00:00");

function toSt(n) {
 s=""
 if(n<10) s+="0"
 return s+n.toString();
}

function countdown() {
 cl=document.clock;
 d=new Date();
 count=Math.floor((eventdate.getTime()-d.getTime())/1000);
 if(count<=0)
   {cl.hours.value="--";
    cl.mins.value="--";
    cl.secs.value="--";
    return;
  }
 cl.secs.value=toSt(count%60);
 count=Math.floor(count/60);
 cl.mins.value=toSt(count%60);
 count=Math.floor(count/60);
 cl.hours.value=count;    

 setTimeout("countdown()",500);
}
// end hiding script-->
</SCRIPT>
</HEAD>

<BODY  onLoad="countdown()">

<FONT FACE="arial, helvetica" SIZE="-1">
<CENTER>
<P>
<FORM name="clock">
         <TD ALIGN=CENTER><INPUT name="hours" size=0></TD> :
         <TD ALIGN=CENTER><INPUT name="mins" size=0></TD> :
         <TD ALIGN=CENTER><INPUT name="secs" size=0></TD>   
         <TD ALIGN=CENTER><B>Hours</B></TD>  
</FORM>
</CENTER>
</BODY>
</HTML>    

I have tried somehing like this:

    if(count=0){<META HTTP-EQUIV="refresh" CONTENT="0;URL=http://www.example.com/">}

but it needs to be inserted in the HEAD, and it just redirects Please help me... You can do this in php, html or any language where this will work.


Solution

  • For example i want to send a mail every 7 days. i have the page that does it. it just need to be clicked. so when countdown finishes it clicks that and resets the countdown back to 7 days.

    I would use Cron Jobs to do that instead of a Jquery code.

    But, anyways, in regards of what you were asking, the redirecting stuff, you could use the following code which doesn't need to be placed in <head>

    if(count == 0){
        window.location.href="http://example.com";
    }