Buenas tardes:
Tengo un problema, estoy intentando hacer una implementación de código para que, al cerrar una ventana o pestaña, me salga un mensaje para decirme si quiero salir de la página, y si marcas “si”, debe abrir un pop up.
Ya he logrado atrapar el evento del navegador y si cierro me sale el confirm, pero si le doy a si no me muestra el pop up que hago con un window.open.
Me podríais ayudar por favor?
Gracias.
Código Javascript
:
Ver originalvar validNavigation = false;
function endSession() {
if( confirm("¿Desea que busquemos mejores precios?")){
ventanacerrar=window.open("ventanacerrar.php","Pregunta","width=750,height=700,resizable=0");
ventanacerrar.onresize=function()
{
window.resizeTo(300,900);
}
ventanacerrar.focus()
alert("entra");
}else{
return false;
}
}
function wireUpEvents() {
// Attach the event keypress to exclude the F5 refresh
$('body').bind('keypress', function(e) {
if (e.keyCode == 116){
validNavigation = true;
}
});
// Attach the event click for all links in the page
$("a,div").bind("click", function() {
validNavigation = true;
});
// Attach the event submit for all forms in the page
$("form").bind("submit", function() {
validNavigation = true;
});
// Attach the event click for all inputs in the page
$("input[type=submit]").bind("click", function() {
validNavigation = true;
});
window.onbeforeunload = function() {
if (!validNavigation) {
endSession();
}
}
}
$(document).ready(function(){
wireUpEvents();
}