My application is MVC5, I want to alert the user when they close the browser tab. I found this solution Setting onbeforeunload on body element in Chrome and IE using jQuery, works great except I use location.href in few cases (custom command buttons inside Telerik grid). Tried the following:
$(window).bind('hashchange', function() {
validNavigation = true;
});
To avoid asking the user if the want to leave the page. Is there a better way to alert the user before closing the browser tab?