I have a page on which I want to confirm whether the user wants to leave. I have to confirm only when a certain condition is met, so I wrote code like this
var back=false;
back=
window.onbeforeunload = function (e) {
alert(back);
if(back==true)
return false;
};
but it does not work. I mean, when I press the back button, it should always work, and I still get a confirmation message even when I return false. What can be wrong? thank
source
share