Search code examples
javascriptmicrosoft-edgeonbeforeunload

beforeunload in Microsoft Edge not firing


I have beforeunload added in my js code as follows and it works in IE10 I would like to give the user a warning, nothing else

$(document).ready(function () {
    init();
    window.addEventListener("beforeunload", function () {

        if (changeSubmitted) {          
            return 'If you choose to leave, the data entered will not be saved!';

        }
        return true;

    });
});

codepen

However, the event doesn't seem to fire in Edge.


Solution

  • Unfortunately all major browsers removed support for the custom message in onbeforeunload event, now they just show their own generic text. Except of IE :)

    Take a look at browser compatibility list.