How to control browser confirmation dialog on leaving page?

后端 未结 2 1307
灰色年华
灰色年华 2020-12-15 09:51

I know there are a lot of questions regarding this but nothing is answering me right. I want to show a confirmation dialog when user leaves the page. If the user press Cance

2条回答
  •  难免孤独
    2020-12-15 10:20

     window.onbeforeunload = function() {
           if (data_needs_saving()) {
               return "Do you really want to leave our brilliant application?";
           } else {
              return;
           }
        };
    

提交回复
热议问题