I want to prompt user to either logout or stay on page as logged-in. I tried using the following code, but not able to find the correct solution:
window.onbeforeunload = function (e) {
var e = e || window.event;
// For IE and Firefox
if (e) {
e.returnValue = 'Any string';
}
alert(doLogout());
// For Safari
return 'Any string';
};
function doLogout(){
var r=confirm("Press a button!");
alert("confirmResponse: " + r);
return r;
}
When i tried closing the tab/window, it just asks for "This page is asking you to confirm that you want to leave - data you have entered may not be saved". In my code first confirm dialog should be popped up, which is not happening.
Any solutions ?