Javascript 显示确认弹出窗口和禁用单击像Facebook这样的弹出窗口,如何操作?

Javascript 显示确认弹出窗口和禁用单击像Facebook这样的弹出窗口,如何操作?,javascript,html,Javascript,Html,我想用户不能点击确认弹出框的外侧。怎么做?单击“后退”按钮(浏览器)时出现弹出窗口 请提供可运行的代码片段,我们可以在其中看到确认弹出窗口。Facebook使用的不是confirm,而是beforeunload处理程序。可能是 if (window.history && history.pushState) { addEventListener('load', function () { history.pushState(null, null, null);

我想用户不能点击确认弹出框的外侧。怎么做?单击“后退”按钮(浏览器)时出现弹出窗口


请提供可运行的代码片段,我们可以在其中看到确认弹出窗口。Facebook使用的不是
confirm
,而是
beforeunload
处理程序。可能是
if (window.history && history.pushState) {
  addEventListener('load', function () {
    history.pushState(null, null, null);
    addEventListener('popstate', function () {
      var stayOnPage = confirm("Are you sure? Mission will be failed");
      if (!stayOnPage) {
        history.pushState(null, null, null);
      } else {
        window.location = 'google.com';
      }
    });
  });
}