且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

拦截页面退出事件

更新时间:2023-12-04 14:06:29

与Ghommey的答案类似,但这也支持旧版本的IE和Firefox。

Similar to Ghommey's answer, but this also supports old versions of IE and Firefox.

window.onbeforeunload = function (e) {
  var message = "Your confirmation message goes here.",
  e = e || window.event;
  // For IE and Firefox
  if (e) {
    e.returnValue = message;
  }

  // For Safari
  return message;
};