Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何捕获浏览器选项卡的关闭_Javascript - Fatal编程技术网

Javascript 如何捕获浏览器选项卡的关闭

Javascript 如何捕获浏览器选项卡的关闭,javascript,Javascript,我们希望在用户关闭浏览器之前抛出特定消息。是否有一种机制可以在所有主要浏览器(如IE、firefox、chrome、opera)上运行 检查: 从 从 我尝试了以下功能,但它不适用于IE8,最新版本的Opera。我错过了什么?window.onbeforeunload=function(e){var message=“您的确认消息在这里。”,e=e | | | window.event;//对于IE和Firefox,如果(e){e.returnValue=message;}//对于Safari返

我们希望在用户关闭浏览器之前抛出特定消息。是否有一种机制可以在所有主要浏览器(如IE、firefox、chrome、opera)上运行

检查:


我尝试了以下功能,但它不适用于IE8,最新版本的Opera。我错过了什么?window.onbeforeunload=function(e){var message=“您的确认消息在这里。”,e=e | | | window.event;//对于IE和Firefox,如果(e){e.returnValue=message;}//对于Safari返回消息;}@塞缪尔:看起来Opera不支持onbeforeunload(参考:)。我尝试了以下功能,但它不适用于最新版本的IE8。我错过了什么?window.onbeforeunload=function(e){var message=“您的确认消息在这里。”,e=e | | | window.event;//对于IE和Firefox,如果(e){e.returnValue=message;}//对于Safari返回消息;}@塞缪尔:看起来Opera不支持
onbeforeunload
(参考:)。
window.onbeforeunload = function (e) {
  var e = e || window.event;

  if (has_message_to_throw) {

    // For IE and Firefox
    if (e) {
      e.returnValue = 'Specific message';
    }

    // For Safari
    return 'Specific message';

  }


};
window.addEventListener("beforeunload", function (e) {
  var confirmationMessage = "\o/";

  (e || window.event).returnValue = confirmationMessage;     //Gecko + IE
  return confirmationMessage;                                //Webkit, Safari, Chrome etc.
});