I tried onbeforeunload as it requires once user-interaction to call, is there any way to call an event without user-interaction as the user exit the browser after it opens the application tab. Or Any other solution without using onbeforeunload that prevents the user to exit the browser.
window.onbeforeunload = function (event) {
var message = 'Important: Please click on \'Save\' button to leave this page.';
if (typeof event == 'undefined') {
event = window.event;
}
if (event) {
event.returnValue = message;
}
return message;
};
$(document).ready(function(){
$(".label").click(function(){
alert('label');
window.onbeforeunload = null;
}
);
$(".new_cont").click(function(){
alert('new_cont');
window.onbeforeunload = null;
}
);
})