WeChat applet prevents users from returning to the previous page and pops up a window for users to confirm whether they want to return to the previous page

Call the enableAlertBeforeUnload method of WeChat in onload. When entering for the first time, it will automatically monitor the current page. When returning, a pop-up window will automatically pop up to prevent the user from returning to the previous page. Click OK to return to the previous page, and cancel to stay on the current page.

onLoad: function(){
    
    
    wx.enableAlertBeforeUnload({
    
    
      message: "返回上页时弹出对话框1212",
      success: function (res) {
    
    
        console.log("方法注册成功:", res);
      },
      fail: function (errMsg) {
    
    
        console.log("方法注册失败:", errMsg);
      },
    });
}

Guess you like

Origin blog.csdn.net/xiaokangna/article/details/132139589