区分使用 window.close 和其他方式关闭窗口(例如单击十字)

发布于 2024-12-19 08:24:20 字数 611 浏览 2 评论 0原文

我想知道窗口是使用 window.close() 关闭还是手动关闭(例如单击十字或刷新,或 Alt + F4)。为此,我可以检查是否调用了 unload 事件,因为当我检查 Chrome 时,执行 window.close() 时未调用 unload 事件

<!doctype html>
<html>
<head>
<script src="jquery-1.6.2.min.js"></script>
<script>
$(document).ready(function(){
$('#close').click(function(){
    window.close();
});
$(window).unload(function(){
    alert("hello");
});
});
</script>
</head>
<body>
<input type="button" id="close" value="close"/>

</body>
</html>

我想知道这是否是指定的行为,或因浏览器而异

I wish to find out whether the window was closed using window.close() or by manually (like clicking on the cross or refreshing, or Alt + F4). For that, I can check whether the unload event is called, because, as I checked for Chrome, the unload event is not being called when window.close() is being executed

<!doctype html>
<html>
<head>
<script src="jquery-1.6.2.min.js"></script>
<script>
$(document).ready(function(){
$('#close').click(function(){
    window.close();
});
$(window).unload(function(){
    alert("hello");
});
});
</script>
</head>
<body>
<input type="button" id="close" value="close"/>

</body>
</html>

I wanted to know whether this is specified behaviour, or varies with browsers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文