本文介绍了在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中关闭窗口之前显示警告消息
发布评论