Is there currently a working way so that when you try to close a site, a window pops up with the message of the desired text, for example, “Do you want to leave?”? I re-read and tried many things, especially with onbeforeunload, and did not find anything adequate, the window pops up with random text (and in all browsers differently), and it works when the page is reloaded and when you go to any page of the site, in general it's not that.
Maybe someone has some interesting idea how to make this window yourself, if there is no normal solution?
- The displayed text you can not change. And then when to show this message, you decide. - Stepan Kasyanenko
- Here is a good option - github.com/carlsednaoui/ouibounce - soledar10
- or is this an option? codepen.io/topicstarter/pen/Qrbbzy?editors=1000 - user33274
- Stepan Kasyanenko, so it works when you go to another page of the site and when you reload the page, if I understood you correctly. How exactly to make that only when you close the page work? - KvinT 2:21 pm
- The remaining methods work when the focus is lost ... It's not that ... - KvinT
|
1 answer
Something like that:
<script type="text/javascript"> $(document).ready(function () { $(window).on('beforeunload', function() { document.write('<div>.....................</div>'); // HTML код в одну строчку!!! return "Вы точно решили покинуть наш сайт?"; }); $('a').click(function() { $(window).off('beforeunload'); }); }); </script> |