Onbeforeunload on safari does not display confirmation message

I have this piece of code that works in all browsers except Safari 10.* (iOS and OSX)

The problem is that Safari fires the beforeunload event but does not appear in the confirmation message

 function goodbye(e) { console.log("goodbye"); en = false; e = e || window.event; e.cancelBubble = true; e.returnValue = msg; if (!en) { e.preventDefault(); if(e.stopPropagation) e.stopPropagation(); return e.returnValue; } } jQuery(window).bind("beforeunload", goodbye); 

A good message is displayed from the console, so the event is fired in Safari, but the confirmation message (also trying to return confirm(msg); instead of return e.returnValue; ) is not displayed. Spent many hours on this and saw a lot of questions here on SO, but no one seems to have a working solution.

EDIT

something strange happens here. If I load the page and refresh once, a message appears, and then if I leave the page by pressing the leave button and re-refresh it on the same tab of the window, the message will not appear.

+2
source share

Source: https://habr.com/ru/post/1260728/


All Articles