I am using window.onbeforeunload method to show confirm message if user leaves website.
window.onbeforeunload = function(e) {
return textMsg;
};
Try (untested code):
window.onbeforeunload = function(e) {
return textMsg;
};
$('a:not([href^="http"])').on('click', function() {
window.onbeforeunload = null; // prevent message
});
$('form').on('submit', function() {
window.onbeforeunload = null; // prevent message
});
This will prevent the event from triggering if links do not start with http
(external links) and for <form>
submits. Looking for a solution for window closing at the moment.