N
N
Nadim Zakirov2021-03-13 12:33:28
JavaScript
Nadim Zakirov, 2021-03-13 12:33:28

How to protect a page from being accidentally closed in Google Chrome?

Tried like this:

window.addEventListener('beforeunload', function() {
    event.preventDefault();
    confirm('Действительно закрыть приложение? Все данные будут потеряны!');
});

But alas, apparently it is necessary somehow differently. If not difficult, can someone provide a working example?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nadim Zakirov, 2021-03-13
@zkrvndm

Thanks everyone, got it. It should turn out like this:

window.onbeforeunload = function() {
  return false;
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question