Skip to content

Instantly share code, notes, and snippets.

@jfreites
Created July 25, 2013 15:10
Show Gist options
  • Save jfreites/6080681 to your computer and use it in GitHub Desktop.
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)
// 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