I have tests that go timer and the result is displayed in a modal window. If you use this example which says a lot on the Internet,

function Unloader(){ var o = this; this.unload = function(evt) { var message = "Вы уверены, что хотите покинуть страницу оформления заказа?"; if (typeof evt == "undefined") { evt = window.event; } if (evt) { evt.returnValue = message; } return message; } this.resetUnload = function() { $(window).off('beforeunload', o.unload); setTimeout(function(){ $(window).on('beforeunload', o.unload); }, 2000); } this.init = function() { $(window).on('beforeunload', o.unload); $('a').on('click', function(){o.resetUnload}); $(document).on('submit', 'form', function(){o.resetUnload}); $(document).on('keydown', function(event){ if((event.ctrlKey && event.keyCode == 116) || event.keyCode == 116){ o.resetUnload; } }); } this.init(); } $(function(){ if(typeof window.obUnloader != 'object') { window.obUnloader = new Unloader(); } }) 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 

Then I get a redirect when this confirmation is also included, but how to avoid it and turned on when he leaves the site did not pass the test. If it is not clear then when he still passes the test in this case so that there is a confirmation for the update, and when the test is over and the timer does not tick.

  • 2
    you are very difficult to read - Jurij Jazdanov

1 answer 1

Catch the event of closing the browser tab with your site and if the visitor is on the page with questions (or already run out of time), throw out an alert indicating that the visitor did not pass this test.

  • I did, but I have an alert in the form of a modal window, my newly written solution. And it will be released that it will pop up 2 times, uncomfortable - Ruslan
  • In order not to jump out two times, you need to place a global variable somewhere that will store the bool value - whether your modular window has already been displayed or not. - Mursalov Oleg