Onunload function and onbeforeunload function do not work when the page is closed?

  node.js, question
window.onbeforeunload = function(){
 alert(1122);
 bracket
 
 How to solve the problem if the browser does not execute alert?

Since 25 May 2011, the HTML5 specification states that calls to window.alert(), window.confirm(), and window.prompt() methods may be ignored during this event. See the HTML5 specification for more details.

MDN

You can directly in the function insidereturn "123"A prompt will be generated.