I want to create a custom modal window that will display when the user closes the Chrome Tab where the app is running (clicks the X) and says "Are you sure you want to close?". However, no matter what I have tried, I either keep getting the default Chrome "are you sure you want to leave this site" message, or it just closes the window with no modal showing up.
I have this code firing when the window is going to close:
window.onbeforeunload = function(e) {
e.preventDefault();
$('#myModal').show();
};
I have read that "onbeforeunload" doesn't work anymore, specifically from here: https://developers.google.com/web/updates/2017/03/dialogs-policy. I haven't gotten any of the alternatives to work though.
Is there something that I am not getting? I've been at this for hours now and have made no progress.