I apologize for this dumb question. i have this simple code:
window.onbeforeunload = function(){
return 'Are you sure you want to leave?';
};
now i want to put some series of codes AFTER the user selects "Leave this page".
I know we can use this:
window.onunload = function(){
alert('bye');
};
but window.onunload only works when the page is refreshed or redirected but not when the browser is closed.
i've also tried this:
window.onbeforeunload = function(){
if(confirm('are you sure?'))
alert('exit') //perfectly works
else
return false //will display the popup "Stay/Leave" with the message "false" - this is not what i expect
//preventDefault() -got some error,
};
what is the best way to add codes AFTER the user clicks "Leave this page"?
OR
is it possible to capture the selection of the user whether STAY or LEAVE?
the whole point is to do something after the user selects any of the options