如何在 Firefox 浏览器中检测浏览器关闭事件?我想在服务器端进行一些清理过程,并维护上次注销时间。
为了实现这一点,需要在用户单击注销或关闭浏览器时触发 ajax 调用。
对于 IE,以下代码有效:
if (window.event.clientY < 0 && (window.event.clientX > (document.documentElement.clientWidth - 5) || window.event.clientX < 0)) {
logoutUser();//logging out the user
}
}
function logoutUser(){
var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera,
//Safari
xmlhttp = new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", "Logout.action", true);
xmlhttp.send();
}
如何在 Firefox 中执行此操作?请帮我。
Use onbeforeunload
window.onbeforeunload = function (e) {
e = e || window.event;
// For IE and Firefox prior to version 4
if (e) {
e.returnValue = 'Any string';
}
// For Safari
return 'Any string';
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)