I have a timer script that I am trying to alter to be more functional for my website.
I am trying to pass a variable (php page location) to the timer so that when it times out it will load a certain page. This page will vary depending on why the timer was initiated.
here is the code:
[CODE]<SCRIPT LANGUAGE = “JavaScript”>
<!–
//var page = ‘../index.php’
var secs
var timerID = null
var timerRunning = false
var delay = 1000
function InitializeTimer(page)
{
// Set the length of the timer, in seconds
secs = 10
StopTheClock()
StartTheTimer(page)
}
function StopTheClock()
{
if(timerRunning)
clearTimeout(timerID)
timerRunning = false
}
function StartTheTimer(page)
{
if (secs==0)
{
StopTheClock()
window.open(page, ‘_self’)
// Here’s where you put something useful that’s
// supposed to happen after the allotted time.
// For example, you could display a message:
}
else
{
secs = secs – 1
timerRunning = true
timerID = self.setTimeout(“StartTheTimer()”, delay)
}
}
//–>
</SCRIPT>
here is the code to execute the script:
[CODE]
<script language=”javascript”>InitializeTimer(“../index.php”)</script>
with this the timer still works and tries to got to the new page but the “page cannot be found” error comes up and in the address field shows “undefined” at the end of my url address.
Can anyone tell me what I am doing wrong. Is there a problem with the type of characters that I can pass to the function? Can I carry a variable through 2 functions as I have in the above code?
Cheers