[英]Detect close tab/browser without message etc?
I would like doing in javascript (jQuery): 我想用javascript(jQuery)做:
if (close tab || close window) {
$.ajax({
type: "POST",
url: "process_form.php",
data: dataString
});
}
Is this possible without message if you want leave page etc? 如果您想离开页面等,这可能没有消息吗?
There is only one useful event you can rely on for that reason, onbeforeunload
. 因此,只有一个有用的事件
onbeforeunload
可以依赖。
window.onbeforeunload = function() {
$.ajax({});
};
Unless you explicitly return false
from that event, there is no message to the user. 除非您从该事件中显式返回
false
,否则不会向用户发送任何消息。 You might want to create a synchronised request anyway, because the browser will not wait for an asyncronous request to finish. 您可能还是要创建一个同步请求,因为浏览器不会等待异步请求完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.