View Full Version : How to make a javascript delay?
Elmore
02-11-2003, 11:41 AM
Hi!
I'd like to make a delay by using a javascript.
I'd like to make a link that goes to a page after
a set delay.
I found some tutorials for it but didn't succeed.
(i'm trying to make a swish button that has a delay)
I'm sure you all know this :) so enlighten me!
Danne
02-11-2003, 12:02 PM
You can use setTimeout:
function openLink(link)
{
setTimeout("self.location="+link, 200); // 200 Milliseconds
}
</script>
<a href="javascript: openlink('whatever.html');">Go to page</a>
Cut the spaces in the <a href=""> if it doesn't work..
Code_gate
02-11-2003, 12:19 PM
I believe this might work. The script is set for a 5 second delay. To change the amount of time simply modify the line that reads setTimeout( "timedRedirect()", 5*1000 ); and change the 5 to the number of seconds you wish for the delay to take.
<script language="JavaScript">
<!--
var sTargetURL = "done.html";
function doRedirect()
{
setTimeout( "timedRedirect()", 5*1000 );
}
// There are two definitions of 'timedRedirect', this
// one adds to the visitors page history.
function timedRedirect()
{
window.location.href = sTargetURL;
}
//-->
</script>
<script language="JavaScript1.1">
<!--
function timedRedirect()
{
window.location.replace( sTargetURL );
}
//-->
</script>
</head>
<a href="javascript:doRedirect()">Click Me</a>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.