0

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.

snowfi6916
  • 697
  • 4
  • 9
  • 21
  • Please see below link for your query. https://stackoverflow.com/questions/10311341/confirmation-before-closing-of-tab-browser – Faseeh Haris Sep 23 '19 at 16:55

1 Answers1

0

Try this:

 window.onbeforeunload = function(e) {
        alert();// your modal -> $('#myModal').show();
        return false; 
    }
Praveen Gopal
  • 529
  • 8
  • 23