javascript确认对话框,然后关闭浏览器窗口 [英] javascript confirm dialog box before close browser window

查看:45
本文介绍了javascript确认对话框,然后关闭浏览器窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用javascript或PHP关闭浏览器窗口之前,我需要显示一个确认对话框.当我单击浏览器的关闭按钮时,将出现确认框;否则,不应显示该对话框.

I need to display a confirm dialog box before closing the browser window using javascript or PHP. The confirm box should come up when I click the close button of browser; otherwise, the dialog should not be displayed.

谢谢

推荐答案

这将在关闭浏览器时显示:

This will display it when closing the browser:

window.onbeforeunload = function (event) {
  var message = 'Sure you want to leave?';
  if (typeof event == 'undefined') {
    event = window.event;
  }
  if (event) {
    event.returnValue = message;
  }
  return message;
}

这篇关于javascript确认对话框,然后关闭浏览器窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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