区分使用 window.close 和其他方式关闭窗口(例如单击十字)
我想知道窗口是使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论