我想检测页面是刷新还是关闭。关闭时,我正在清除会话。但我的会话也清楚了解浏览器刷新。我已搜索但未找到任何解决方案。
我用各种方法解决: -
方法1 (这项工作,但在刷新时也会讨论。)
function HandleOnClose(event) /*called on onbeforeunload on body*/ {
if (event.clientY < 0) {
var request = GetRequest();
Urladd = "logout url goes here" //logiut URL work fine
request.open("POST", Urladd, false);
request.send();
}
}
function GetRequest() {
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
方法2: How to know whether refresh button or browser back button is clicked in firefox