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.