Here is the function I am using to detect when a form is closing:
window.onbeforeunload = function (e) {
var y = e.pageY || e.clientY; //window.event.clientY; //
if (y < 0) {
return 'Window closed';
}
else {
return 'Are You Sure Wants To Close Form?';
}
};
Currently, it only displays a popup with the text "Are You Sure Wants To Close Form?". However, I would like to perform a task if the user chooses to leave the page. How can I achieve this?