window.onbeforeunload = function (e) {
// Get the current domain
var currentDomain = window.location.hostname;
// Get the element the user clicked (if it's a link) or if the window is closing
var newUrl = document.activeElement.href;
// If the user is navigating to a new URL and it contains the same domain, don't prompt
if (newUrl && newUrl.indexOf(currentDomain) !== -1) {
return; // No prompt, within the same domain
}
// Otherwise, show a prompt if they are leaving the site or closing the tab
var message = "Are you sure you want to leave this page?";
e = e || window.event;
// For older browsers
if (e) {
e.returnValue = message;
}
// For newer browsers
return message;
};
Editor is loading...