javascript – Confirrm box when the exit button is clicked. I want some action to happen when the user press confirm

I am doing some code and trying to do some actions after the user press the exit button, but i cant seem to make it work.

I want when the user press teh exit button, a confirm box to appear and then an action should happen if they press cancel or confirm

This is my code:

window.onbeforeunload = function () {


const leavePage = confirm("some message");
if (leavePage) {
action1();
} else {
action2();
}
});


} 

If the confirm dont work on onbeforeunload, what can i do to make what i want to work?

Product of the Month September 2016

Source link

Leave a Comment

Your email address will not be published. Required fields are marked *