Why does onbeforeunload, always return the default statement, why does the custom statement not work?

window.onbeforeunload = function (e) {
        var message = "";
        e = e || window.event;
    
        if (e) {
            e.returnValue = message;
        }
    
        return message;
    };
window.onbeforeunload = function (e) {
  e = e || window.event;

  // IE8Firefox 4
  if (e) {
    e.returnValue = "";
  }

  // Chrome, Safari, Firefox 4+, Opera 12+ , IE 9+
  return "";
};
<body onbeforeunload="return myfunction()">
 
<script>
function myfunction() {
    return "";
}
</script>

none of these three ways works, only the browser"s default prompt "OK to leave." Ie,chrome,360,edge can"t even display custom content?

Apr.11,2021

not someone has already told you your last question. The new version of the browser beforeunload will no longer display custom content.

starting with Firefox 4, Chrome 51, Opera 38, and Safari 9.1, the generic confirmation message replaces the string returned by the event.
Menu