3

I implemented to save the changes on on refresh/close event as :

@HostListener('window:beforeunload', ['$event'])
  beforeunloadHandler(event) {
    //save the form to local storage
    event.returnValue = false;
    }

It is working fine but the save happens on both reload/cancel click. enter image description here

Is there a way to differentiate between reload and cancel click?

The example here! shows the above warning on every page refresh and also on navigating backward using browser back button, But the same is only working for me for one time refresh and browser close event.

I am missing here something or chrome/firefox has restricted this onbeforeunload event to refresh and close?

Thanks.

Shruti
  • 75
  • 10
  • Since you put angular tag here I will add this - https://angular.io/api/router/CanDeactivate. Maybe this is not exactly what you want but if you use angular it should prevent routing while eg. data is not saved. – Buczkowski Sep 18 '18 at 19:12
  • Why not just save data regardless? Actually why not save it at set intervals? – Lazar Ljubenović Sep 18 '18 at 20:15

0 Answers0