Is there any way that I could detect in the following code that either user clicked "leave page" or "stay on page" button ?
$(window).on('beforeunload', function (){
return "You save some unsaved data, Do you want to leave?";
});
Is there any way that I could detect in the following code that either user clicked "leave page" or "stay on page" button ?
$(window).on('beforeunload', function (){
return "You save some unsaved data, Do you want to leave?";
});
With a few hacks you can at least determine if the user stayed.
If the user left the page, there's not much you can do about that :
var timeout;
$(window).on('beforeunload', function (){
timeout = setTimeout(function() {
// user stayed, do stuff here
}, 1000);
return "You save some unsaved data, Do you want to leave?";
});
iirc, the unload event is not triggered, when the user decides to stay on the page. so:
$(window).on('unload', function (){
// user has left the page, do stuff here
}