1

On my website on the payment page if the user tries to page refresh shows the alert popup.

when user refresh the page show this popup

All browsers working properly but not show only Safari 14. If my console menu open that time working fine.

My code I tried option 1: Not working in safari 14

 @HostListener('window:beforeunload', ['$event'])
  unloadHandler($event) {
    $event.preventDefault(); 
    $event.returnValue = 'Your data will be lost!'; 
  }

I also tried option 2: Not working in safari 14

  window.addEventListener('beforeunload', function (e) {
      e.preventDefault();
      e.returnValue = '';
    });

Both solutions working fine but not working in safari 14.

Please any solution.

Thank you

Vijay Prajapati
  • 738
  • 1
  • 7
  • 20
  • Here is an SO question that may help: https://stackoverflow.com/questions/14645011/window-onbeforeunload-and-window-onunload-is-not-working-in-firefox-safari-ope – Maxime Chevallier Feb 18 '21 at 13:55
  • Yes, Maquessime Chevallier, I am already trying this... Issue only in safari 14. – Vijay Prajapati Feb 18 '21 at 13:57
  • https://caniuse.com/mdn-api_window_beforeunload_event_event_returnvalue_activation The support for this on Safari is unknown and the feature is considered to be deprecated and obsolete. Do you have an expectation that this should work on that version? – possum Feb 18 '21 at 14:05
  • Seems indeed to be horribly broken in Safari 14. I only randomly see the beforeunload handler being fired. Tried a *lot* of things: clicking in the window, changing field inputs, changing URL with random GET params etc. I see it fire sometimes, but I can't by the life of me figure out what the condition is. – zmippie Dec 22 '21 at 13:05
  • @VijayPrajapati hey encountering literally same problem right now. Did you find any solution? – Ibrahim Noor Dec 31 '21 at 02:36
  • @lbrahim Noor till now not found any proper solution. – Vijay Prajapati Jan 04 '22 at 17:10

0 Answers0