E
E
Eugene Chefranov2018-02-11 17:03:54
JavaScript
Eugene Chefranov, 2018-02-11 17:03:54

How to confirm closing a tab?

How can I make a close confirmation window appear when I close a tab?

I saw this solution.

window.onunload = function()
{
     return confirm('Вы хотите покинуть сайт?')
}

And such
window.onbeforeunload = function(){ return 'Текст сообщения'; }

But it didn't work for me in Chrome. Probably no longer relevant code for current browsers.

The task is to show the visitor a window before closing the tab with a promotional discount code for the product.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question