U4-10554 - cross-browser

This commit is contained in:
Stephan
2017-10-18 09:29:50 +02:00
parent 24b147e2a6
commit b06d30c0f9

View File

@@ -117,19 +117,27 @@ function valFormManager(serverValidationManager, $rootScope, $log, $timeout, not
});
unsubscribe.push(locationEvent);
var savedUnloadHandler = $window.onbeforeunload;
$window.onbeforeunload = function () {
// try to do it in the most cross-browser way
// some browsers will display their own custom message
// and some will just ignore this completely
function onBeforeUnload(e) {
if (formCtrl.$dirty) {
return "You have unsaved changes."; // most browsers won't display it anyways
var message = "You have unsaved changes.";
e.returnValue = message;
return message;
} else {
return null;
}
}
$window.addEventListener("beforeunload", onBeforeUnload);
//Ensure to remove the event handler when this instance is destroyted
scope.$on('$destroy', function() {
for (var u in unsubscribe) {
unsubscribe[u]();
}
$window.onbeforeunload = savedUnloadHandler;
$window.removeEventListener("beforeunload", onBeforeUnload);
});
$timeout(function(){