在Java Script中关闭窗口之前显示警告消息 [英] Show warning message before close window in Java Script

查看:273
本文介绍了在Java Script中关闭窗口之前显示警告消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过这个:

<body onunload="LogoutNoAsk();"> </body>

,功能是:

function LogoutNoAsk()
{
    alert("Please press the Logout button to logout.");
    parent.close();

}

当我按下关闭时,这是'X'按钮在窗口的右上方,它直接关闭,没有警告信息。怎么了?

When I press close which is the 'X' button on the top right of the window, it close straightaway without the warning message. What's wrong?

推荐答案

你真的想要使用 onbeforeunload 允许您阻止关闭事件的事件。

You're actually wanting to use the onbeforeunload event which allows you to block the close event.

请参阅 MDN参考了解详情,但所需代码为:

See the MDN reference for details, but the code required would be:

window.onbeforeunload = function(e) {
    return 'Please press the Logout button to logout.';
};

这篇关于在Java Script中关闭窗口之前显示警告消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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