用于检查浏览器窗口何时关闭的JavaScript [英] javascript to check when the browser window is close

查看:97
本文介绍了用于检查浏览器窗口何时关闭的JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道我可以使用javascript来检查浏览器窗口何时关闭并弹出确认dailog以询问用户是否确认退出浏览器或改变主意留下来?

Does anyone know any way that I can use javascript to check when the browser window is close and pop-up a confirmation dailog to ask whether the user is confirm to exit the browser or change his mind to stay?

推荐答案

window.onbeforeunload = function (e) {
  var e = e || window.event;

  //IE & Firefox
  if (e) {
    e.returnValue = 'Are you sure?';
  }

  // For Safari
  return 'Are you sure?';
};

https://developer.mozilla.org/en/DOM/window.onbeforeunload

这篇关于用于检查浏览器窗口何时关闭的JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆