Javascript Delayed Redirection (Rated 5)Description:
This will redirect a visitor to a page to another page, after an optional delay.
It's used like this for an immediate redirection.
<script type="text/javascript" src="http://www.pathto/redirect.js"></script>
<script type="text/javascript">
var redirect = new Redirect("www.url.com");
redirect.go(); </script> Code starts here
// JavaScript Document
//-->
// Redirect constructor:
function Redirect( url ) {
this.url = url;
this.secs = 0;
}
// Perform the redirect:
function Redirect_go() {
var url = this.url;
if ( url ) {
var secs = this.secs;
if ( secs == 0 ) {
window.location.replace( url );
} else {
var ms = secs * 1000;
setTimeout( 'window.location.replace( "' + url + '" )', ms );
}
}
}
Redirect.prototype.go = Redirect_go;
// Delay the redirect:
function Redirect_delay( secs ) {
// Try to parse the argument as an integer:
secs = parseInt( secs );
// Test for a non-negative integer:
if ( !isNaN( secs ) && secs >= 0 ) this.secs = secs;
}
Redirect.prototype.delay = Redirect_delay;
// Write a generic redirect message into the current document:
function Redirect_write() {
var url = this.url;
if ( window.location == url ) return;
var secs = this.secs;
}
Redirect.prototype.write = Redirect_write;
Submitted by Devscripts on 13-02-2003 16:41 |