window.onbeforeunload = function(evt) {
var message = 'Are you sure you want to leave the page. All data will be lost!';
if (typeof evt === 'undefined') {
evt = window.event;
}
if (evt && !($("#a_exit").click)) {
evt.returnValue = message;
}
return message;
};
I want the user to leave the page by clicking on the link (only id ="a_exit"). In other cases, such as refreshing the page, clicking on another link, the user will be prompted that he / she wants to leave the page. I tried using the code above. He still asks me if I want to leave when I click on the exit link.
source
share