Is it possible to fire an alert on browser close? If user confirm "reload/close" then want to execute some ajax stuff. This is I have tried so far
window.onbeforeunload = function () {
return 'This will close your chat session. Are you Sure!';
var meta_id = $('#meta_id').val();
$.ajax({
url: site_url + '/chat/send_offline',
type: 'post',
cache: false,
async: false,
data: {
meta_id: meta_id
}
});
}
As far I know code not execute after the return
statement. So is it possible to alert and execute ajax code simultaneously if user confirm??