Here's my firstly:
<?php echo "<script language=\"javascript\" type=\"text/javascript\">
var g_iCount = new Number();
// CHANGE THE COUNTDOWN NUMBER HERE - ADD ONE TO IT //
var g_iCount = 6;
function startCountdown(){
if((g_iCount - 1) >= 0){
g_iCount = g_iCount - 1;
numberCountdown.innerText = 'You must wait ' + g_iCount +' seconds before your download starts';
setTimeout('startCountdown()',1000);
}
}
function top() {
setTimeout('startCountdown()',0000);
setTimeout('delayer()',6000);
}
function delayer() {
window.location = \"http://www.mediaphiles.net/uploads/".$actualname."\"
}
</script>";
?>
Don't worry about the $actualname variable, that is working. What I have it doing is when you click a button it starts top() which starts the countdown. Then, after 5 seconds (6 seconds) it redirects. But it doesn't seem to be working.
-- I'm new to Javascript so I have no idea what the problem is.
xelawho 12-24-2011, 11:56 PM I think it was a problem with the string redirect string at the end. Also innerText is not so widely used. I don't know about a php echo, but this works as normal js:
<body>
<div id="numberCountdown"></div>
<script type="text/javascript">
var g_iCount = new Number();
// CHANGE THE COUNTDOWN NUMBER HERE - ADD ONE TO IT //
var g_iCount = 6;
function startCountdown(){
if((g_iCount - 1) >= 0){
g_iCount = g_iCount - 1;
document.getElementById("numberCountdown").innerHTML = 'You must wait ' + g_iCount +' seconds before your download starts';
setTimeout('startCountdown()',1000);
}
}
function top() {
setTimeout('startCountdown()',0000);
setTimeout('delayer()',6000);
}
function delayer() {
window.location = 'http://www.mediaphiles.net/uploads/'+.$actualname;
}
</script>;
</body>
xelawho 12-25-2011, 12:06 AM although setting two timeouts counting down to the same event seems a little excessive to me, and calling a function from within itself doesn't make much sense when you can use SetInterval...
<body>
<div id="numberCountdown"></div>
<script type="text/javascript">
// CHANGE THE COUNTDOWN NUMBER HERE - ADD ONE TO IT //
var g_iCount = 6;
function startCountdown(){
if((g_iCount - 1) >= 0){
g_iCount = g_iCount - 1;
document.getElementById("numberCountdown").innerHTML = 'You must wait ' + g_iCount +' seconds before your download starts';
} else {
window.location = 'http://www.google.com'
}
}
function top() {
startCountdown();
setInterval(startCountdown,1000);
}
top();
</script>;
</body>
Last one works, but it continuously redirects and the link it redirects to is a download link so it downloads 1,2,3,4,5 (and so on) files.
Logic Ali 12-26-2011, 02:50 AM Last one works, but it continuously redirects and the link it redirects to is a download link so it downloads 1,2,3,4,5 (and so on) files.The interval needs to be cancelled.
Try this. The 'seconds' display replaces the @ in the message.
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<span id='tell'></span><p>
<script type='text/javascript'>
function timedRedirect( secs, elemId, msg, newURL )
{
var period,
remain = secs,
msgParts = msg.split( '@' ),
elem = document.getElementById( elemId );
function f()
{
elem.innerHTML = msgParts[ 0 ] + remain + msgParts[ 1 ];
if( remain-- == 0 )
{
clearInterval( period );
location.href = newURL;
}
}
function installHandler( obj, evt, func )
{
window.attachEvent ? obj.attachEvent(evt,func) : obj.addEventListener( evt.replace( /^on/i, "" ), func, false);
}
installHandler( window, 'onload', function(){ period = setInterval( f, 1000 ) } );
}
timedRedirect( 5, 'tell', 'Seconds remaining before redirection: @', 'http://disney.com' );
</script>
</body>
</html>
The interval needs to be cancelled.
Try this. The 'seconds' display replaces the @ in the message.
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<span id='tell'></span><p>
<script type='text/javascript'>
function timedRedirect( secs, elemId, msg, newURL )
{
var period,
remain = secs,
msgParts = msg.split( '@' ),
elem = document.getElementById( elemId );
function f()
{
elem.innerHTML = msgParts[ 0 ] + remain + msgParts[ 1 ];
if( remain-- == 0 )
{
clearInterval( period );
location.href = newURL;
}
}
function installHandler( obj, evt, func )
{
window.attachEvent ? obj.attachEvent(evt,func) : obj.addEventListener( evt.replace( /^on/i, "" ), func, false);
}
installHandler( window, 'onload', function(){ period = setInterval( f, 1000 ) } );
}
timedRedirect( 5, 'tell', 'Seconds remaining before redirection: @', 'http://disney.com' );
</script>
</body>
</html>
Thanks but if I wanted that to start when someone clicks a button... what function do I tell it to start?
|
|