Hi,

On Sunday, December 23, 2012 8:28:59 AM UTC+1, dylst wrote:
>
> It seems like the answer was a lot easier than I thought, after digging 
> around for it for quite a while.
> I have the following two methods in my controller to confirm 
> location/window change events away from the current location/page
>
>     var leavingPageText = "You'll lose your changes if you leave";
>     window.onbeforeunload = function(){
>         return leavingPageText;
>     }
>

Don't forget to clear window.onbeforeunload or else it may misfire when the 
user has already
navigated away from the view:

$scope.$on('$destroy', function() {
    window.onbeforeunload = undefined;
});

    $scope.$on('$locationChangeStart', function(event, next, current) {
>         if(!confirm(leavingPageText + "\n\nAre you sure you want to leave 
> this page?")) {
>             event.preventDefault();
>         }
>     });
>

Andreas

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to