在Java Script中关闭窗口之前显示警告消息

编程入门 行业动态 更新时间:2024-10-26 21:24:44
本文介绍了在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中关闭窗口之前显示警告消息

本文发布于:2023-10-16 06:09:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1496715.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:关闭窗口   消息   Java   Script

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!