FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


JavaScript Countdown Timer Help!





Jigsaw
Hello,

I'm new to this forum. I'm a student in Computer Science at my High School, and I truely love to learn anything about computers.

My question is:

On one of my pages I have a text with an audio file that accompanies the text. At the end of the text is a riddle.

I want to put a timer (that displays 2 minutes worth of time) and once the 2 minutes are gone I want the browser to close or I want to be redirected to another page that reads (game over).

It's a website in tribute to the sAW francise.

If someone could guide me to writing the code in either JavaScript or PHP that would be awesome.

Thanks in advance.
bartdou
comes later, hope it still can help:
Code:
<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="gb2312">
<head>
<head>
<title>JavaScript Countdown Timer </title>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<meta name="author" content=",CNLei.y.l@gmail.com">
<meta name="keywords" content="" />
<meta name="description" content="" />
<script language="JavaScript">
<!-- //
function GetRTime(){
var EndTime= new Date(2007,5,10,0,0); //up to:2006-6-10 00:00
var NowTime = new Date();
var nMS =EndTime.getTime() - NowTime.getTime();
var nD =Math.floor(nMS/(1000 * 60 * 60 * 24));
var nH=Math.floor(nMS/(1000*60*60)) % 24;
var nM=Math.floor(nMS/(1000*60)) % 60;
var nS=Math.floor(nMS/1000) % 60;
if(nD>= 0){
 document.getElementById("RemainD").innerHTML=nD;
 document.getElementById("RemainH").innerHTML=nH;
 document.getElementById("RemainM").innerHTML=nM;
 document.getElementById("RemainS").innerHTML=nS;
}
else {
 document.getElementById("CountMsg").innerHTML="it ended!";
}
setTimeout("GetRTime()",1000);
}
window.onload=GetRTime;
// -->
</script>
</head>
<body>
<div id="CountMsg">2006籭<strong id="RemainD">XX</strong>days<strong id="RemainH">XX</strong>hours<strong id="RemainM">XX</strong>minutes<strong id="RemainS">XX</strong>seconds</div>
</body>
</html>
<label id="leftTime1"></label>
<script language="javascript" type="text/javascript">
var auctionDate = 5450;
var showTimeElement = new Array();
showTimeElement[0] = "leftTime1";
//showTimeElement[1] = "leftTime2";
var _day = '';
var _hour = 'Сʱ';
var _minute = '';
var _second = '';
var _end = 'ѿʼ';
var startTime = (new Date()).getTime();
var Temp;
var timerID = null;
var timerRunning = false;
function showtime()
{
now = new Date();
var ts=parseInt((startTime-now.getTime())/1000)+auctionDate;
var dateLeft = 0;
var hourLeft = 0;
var minuteLeft = 0;
var secondLeft = 0;
if(ts < 0)
{
ts = 0;
CurHour = 0;
CurMinute = 0;
CurSecond = 0;
} else {
dateLeft =parseInt(ts/86400);
ts = ts - dateLeft * 86400;
hourLeft = parseInt(ts/3600);
ts = ts - hourLeft * 3600;
minuteLeft = parseInt(ts/60);
secondLeft = ts - minuteLeft * 60;
}
if(hourLeft < 10) hourLeft = '0' +hourLeft;
if(minuteLeft < 10) minuteLeft = '0' +minuteLeft;
if(secondLeft<10) secondLeft='0'+secondLeft;
if( dateLeft > 0 )
dateLeft = dateLeft + _day ;
else
dateLeft = "";
if( hourLeft > 0 )
hourLeft = hourLeft + _hour ;
else
{
if( dateLeft != "" )
hourLeft = "00" + _hour;
else
hourLeft = "";
}
if( minuteLeft > 0 )
minuteLeft = minuteLeft + _minute ;
else
{
if( dateLeft !="" || hourLeft != "")
minuteLeft = "00" + _minute;
else
minuteLeft = "";
}
if( secondLeft > 0 )
secondLeft = secondLeft + _second ;
else
{
if( dateLeft !="" || hourLeft != "" || minuteLeft != "")
secondLeft = "00" + _second;
else
secondLeft = "";
}
if (dateLeft == '') {
Temp=dateLeft+hourLeft+minuteLeft+secondLeft ;
}else {
Temp=dateLeft+hourLeft;
}
if(auctionDate <= 0 || dateLeft <=0 && hourLeft<=0 && minuteLeft<=0 && secondLeft <=0)
{
Temp = "<strong class=\"H\">"+_end+"</strong>";
stopclock();
}
for (var iii = 0; iii < showTimeElement.length; ++iii)
{
var showTime = showTimeElement[iii];
if (document.getElementById(showTime)) document.getElementById(showTime).innerHTML=Temp;
}
timerID = setTimeout("showtime()",1000);
timerRunning = true;
}
var timerID = null;
var timerRunning = false;
function stopclock()
{
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}
function macauclock()
{
stopclock();
showtime();
}
function onloadall()
{
macauclock();
try
{
initprovcity();
}
catch(e)
{
}
}
try
{
onload=onloadall();
}
catch(e)
{
}
</script>
Related topics
Reply to topic    Frihost Forum Index -> Lifestyle and News -> Jobs and Learning

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.