Hi all,
My issue is window.onbeforeunload is triggering twice and so dialog window is shown twice which should not happen. i have tried all possible ways to prevent that event to fire but nothing is working. so planned to handle the navigation using angular. Is there any way to handle the page unload in angular ?
I have tried using $destroy, but its not working..
Thanks in advance

Vinay SinghPosted Jul 19, 2016, 5:30 AM
Prathaban DuraiPosted Jul 26, 2016, 2:16 AM
$scope.currentLocation = $location.url();
$scope.$on("$locationChangeSuccess", function handleLocationChangeStartEvent(event) {
$scope.currentLocation = $location.url();
})
var startWatchingTimer = $timeout(startWatchingForLocationChanges, 0, false);
var stopWatchingLocation = null;
function handleLocationChangeStartEvent(event) {
event.preventDefault();
var targetPath = $location.path();
if ($scope.currentLocation != targetPath)
{
if (unsaved) {
var temp = confirm("Do you want to leave the page? /n All the unsaved data will be lost")
if (temp) {
$location.path(targetPath);
stopWatchingLocation();
$scope.$applyAsync(startWatchingForLocationChanges);
}
else {
window.stop();
}
}
}
}
//
function startWatchingForLocationChanges() {
stopWatchingLocation = $scope.$on("$locationChangeStart", handleLocationChangeStartEvent)
}