0

I have an AngularJS application with multiple views (using ng-view). In the app's javascript file, I have intercepted the window's OnBeforeUnload event to make sure the user does not leave the site without saving his work. However, I have noticed that the OnBeforeUnload event gets fired at weird times in IE9 (e.g., when the Angular view changes, or when the view is refreshed).

Basically, OnBeforeUnload is firing when it shouldn't be.

So far, I have worked around the problem by setting and clearing flags in the the routeChangeStart and routeChangeSuccess events, but there always seems to be another gotcha.

Has anyone else seen this problem?

Thanks in advance....

Ash8087
  • 643
  • 6
  • 16

1 Answers1

0

I had a similar problem. After searching about that, I realized that window.onbeforeunload executes even when you refresh a view. In the other hand, about the code being executed at weird times, I think you need to use $rootScope.$apply:

window.onbeforeunload = function () {
    $rootScope.$apply(function () {
        //Your code here
    }
}

source: The view is not updated in AngularJS

Community
  • 1
  • 1