This question has already been answered:

Good time!

There is a html form. It has a focus loss event. After it there is a check for correctness of filling, if there are errors, pops up alert. The problem is that switching the tab in the browser is also perceived as a loss of focus of the form. If the form has the focus and at this point the user switches the tab, the test starts and the alert pops up. In Mozilla, this is all tolerable, it does not interfere with switching the tab, but in chrome, the alert does not allow you to leave the current page. If you do not prohibit the display of pop-up windows, but simply click on OK, the test works out time after time and the window is displayed again and again.

I tried to attach some check for switching the tab, but: 1 - the switch event works after the event of loss of focus of the form 2 - if you click on the alert, the tab again receives focus and the check is restarted.

Tell me, how can I solve this problem?

Reported as a duplicate by vp_arth , Grundy members javascript Mar 16 '17 at 10:40 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • Tell me, how can I solve this problem? - do not use alert. This is the best solution. - Grundy
  • @Grundy I'd love to, but alas, this is not my code) - Furry Cat
  • Then for good: no way. - Grundy
  • @Grundy for some reason I thought so ((( - Furry Cat
  • one
    As a workaround, not very good: you can override the alert function: window.alert = function(){...} and in the overridden function you can already define what and how to show. - Grundy

1 answer 1

I had only one idea - to force the focus away from the input field before displaying the alert. Then, at least, the check is not restarted after it is closed. But the problem remains - the focus remains on the current tab and you have to switch again.

  • I don’t understand something: if you can change the handler - why not replace the alert On normal javascript modal windows that do not block the script execution - Grundy
  • @Grundy to change the layout here is much more difficult than to add a couple of lines JS (in organizational terms) - Furry Cat
  • In essence, you can add a dialogue call without changing the layout - Grundy