Created
July 25, 2013 15:10
-
-
Save jfreites/6080681 to your computer and use it in GitHub Desktop.
Un práctico snippet para hacer un redirect usando javascript. Gracias a Zahir Gudiño por compartir (http://gplus.to/zgudino)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Redirect.js | |
// Original from: Zahir Gudiño - http://gplus.to/zgudino | |
// Use: | |
// var redirect = new redirect('302', 'Upps, the site was moved!'); | |
// redirect.to('http://new-url-to-redirect').run(2000); | |
// | |
function Redirect(err, msg) { | |
this.httpstatus = err; | |
this.message = msg; | |
return this; | |
} | |
Redirect.prototype.to = function(url) { | |
message = this.message; | |
error = this.httpstatus; | |
return { | |
run: function(timeout) { | |
$_debug = '-- redireccionando --' + '\n' + | |
'url : ' + url + '\n' + | |
'http status: ' + error + '\n' + | |
'message: ' + message + '\n' + | |
'-- fin --'; | |
console.log($_debug); | |
window.setTimeout(function() { | |
window.location = url; | |
}, timeout); | |
return 'done'; | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment