Vin*_*abu 2 javascript browser firefox jquery dom-events
如何在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();
}
Run Code Online (Sandbox Code Playgroud)
如何在Firefox中执行此操作,帮助我.
提前致谢.
使用 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';
};
Run Code Online (Sandbox Code Playgroud)