I would like to execute a function before leaving page without showing a confirmation popup with Javascript only. I\'ve tried with the code below but it did
Please try below simple code -
Jquery Code Example -
$(window).bind('beforeunload', function(){
Func_ToInsert_Record();
Alert('Thanks And Bye!');
});
Javascript Code Example -
// Anonymous function
window.onbeforeunload = function(event) {
var message = '';
if (window.event) {
console.log(window.event);
console.log(event.currentTarget.performance);
console.log(event.currentTarget.performance.navigation);
console.log(event.currentTarget.performance.navigation.type);
}
event = event || window.event;
event.preventDefault = true;
event.cancelBubble = true;
event.returnValue = message;
}