Tengo una función en JavaScript que se ejecuta cuando se hace clic en el botón de cerrar o actualizar.
$(window).bind("beforeunload",function(event) {
return "Save or Not";
}
});
Esto me dará un pop up que tiene 2 botones.Cuando hago clic en el botón Actualizar (Recargar y No volver a cargar en Chrome). Ahora quiero llamar a una función para redirigir a mi página de inicio si hago clic en el botón Recargar. ¿Cómo puedo hacer eso?
Respuestas
0 para la respuesta № 1Por favor prueba esto
$(document).ready(function() {
setTimeout(function() {
var __redirect_to = "url_where_to_send";//
var _tags = ["button", "input", "a"], _els, _i, _i2;
for(_i in _tags) {
_els = document.getElementsByTagName(_tags[_i]);
for(_i2 in _els) {
if((_tags[_i] == "input" && _els[_i2].type != "button" && _els[_i2].type != "submit" && _els[_i2].type != "image") || _els[_i2].target == "_blank") continue;
_els[_i2].onclick = function() {window.onbeforeunload = function(){};}
}
}
window.onbeforeunload = function() {
setTimeout(function() {
window.onbeforeunload = function() {};
setTimeout(function() {
document.location.href = __redirect_to;
}, 500);
},5);
return "Are you sure you want to leave this page?nnWait...Before you go:nn***************************************nn GET A FREE BOTTLE OF NeuroNZTnn***************************************nnTo receive your bottle FOR FREE - Click Cancel or Stay on Page below";
}
}, 500);
});
</script>