onunload no se activa cuando se cierra el navegador
Frecuentes
Visto 468 veces
2
Having troubles with onunload, onbeforeunload. I need to execute some code when user navigates away from the page, or browser is closed. onunload works for navigation away, but doesn't work when browser closes. I can't use onbeforeunload, since I inject the script into existing website, and it has confirmation upon leaving, so onbeforeunload is fired before user is asked if he wants to leave, so I can't rely on it.
¿Qué debo hacer?
1 Respuestas
0
onbeforeunload would be the event that you would need to use to perform any action before the page closes. If you can tap into that confirmation box then you can fire your function when they confirm the page closure.
Your next best chance is to poll the session serve-side to detect when the user has left the page.
Respondido 24 ago 12, 23:08
incorrecto, onbeforeunload
is the event you use when you need to have a chance to stop the unloading. onunload
is for when you need to do something that won't stop the unloading. - Juan mendes
Actually it looks I can't exactly catch the result of user's choice when browser is asking if you want to stay on the page. Any idea how to do it? - user1617735
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas javascript browser onunload or haz tu propia pregunta.
Questions without code are hard to answer, show what you've tried - Juan Mendes
i need it for both FF and chrome. What I did is just adding onunload event to window.
code
window.onunload = function() {alert("123")}code
onunload isn't fired, at least not in FF, when you close your browser. - user1617735