Hi guys, Shraing Code Snippet for Calling a function before leaving page. It may be required for variety of purposes. you can use it to track statistics for user's leaving from a website page to record that page for bounce pages statistics from where user is leaving website mostly. this is just a simple example you can use it for variety of way.
you can share in comments for which purpose you may require this type of code functionality.
**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;
}