How to display a modal window before closing the site, tried to remake the following script:

window.onbeforeunload = function (){ if(confirm('Π”Π° Π½Π΅ΡƒΠΆΠ΅Π»ΠΈ?')){ return true; } else { return false; } } 

It turned out like this:

 window.onbeforeunload = function (){ $('#myModal').show() } 

But still does not work, how to do it?

    1 answer 1

    This question is not the first time appears here, and not the first time the answer is the same. Modern browsers, if they handle the onbeforeunload event, then no ΠΌΠΎΠ΄Π°Π»ΠΎΠΊ , ajax requests, etc. you cannot commit. All that is in your power is to display the text in the систСмном модальном ΠΎΠΊΠ½Π΅ . Anything more.

    Documentation

    The f-tion should return the text that appears in the modal window; you cannot change the window in any way.

     window.onbeforeunload = function () { return "Π’Π°ΡˆΠ΅ тСкст" } 

    And even then, it does not always work and is not the same.