Show an alert on page close

Goodmorning everyone . I would like to make sure that when a user is trying to close a particular page, a popup comes out (even directly from the browser) asking the user to confirm if he really wants to leave the page.
Kind of like this code would do
window.addEventListener (‘beforeunload’, function (e) {
e.preventDefault ();
e.returnValue = ‘Do you want to leave the page?’;
setTimeout (function () {// Timeout to wait for user response
setTimeout (function () {// Timeout to wait onunload, if not fired then this will be executed
console.log (‘User stayed on the page.’);
}, 50)}, 50);
return ‘Do you want to leave the page?’;

Is it possible to do it in bubble, without using auxiliary plugins? also because these track only when, for example, the mouse reaches the top of the page, but they do not track if it has actually clicked on the closing of the tab.

This topic was automatically closed after 70 days. New replies are no longer allowed.