At the moment, when you try to close the browser tab, it knocks out an alert (are you sure you want to close?), But you need to make sure that the alert does not knock out, the user closes the window, and a new one opens automatically (here - index.html). And will it work in browsers for android? Thank.

window.onbeforeunload = confirm; function confirm() { return window.open("index.html"); } 
  • one
    1. Do not call your functions in the same way as the methods of the window object are called. 2. If the user wants to close the window, you must let him do it. - Igor
  • Afaik, impossible. When you close a window, all its contents, including any running scripts, are destroyed. Well, in general, if such a possibility existed, all virus writers would have used it for a long time. - Yaant
  • @Yaant is possible. The author, in fact, already does this using window.onbeforeunload . - Igor
  • @Igor, hmm, does it really work in modern browsers? - Yaant
  • @Igor, it is impossible if the user clicks on the present form to leave anyway. in this case, the open will not even be executed. In onbeforeunload there are generally a lot of restrictions that can be accomplished - Grundy

0