Ravi Patel

Ravi Patel

  • 247
  • 6.8k
  • 1.4m

javascript ,jquery

Jul 21 2014 8:11 AM
i want to call logout page on browser close or tab close?
 
 
why this code is not working in Firefox an and google chrome  ? but working in IE  on Browser close or tab close
 
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
var clicked = false;
function CheckBrowser() {
if (clicked == false) {
window.location = "../Security/logOut.aspx";
// Browser closed
}
else {
alert('false');
redirected
clicked = false;
}
}
function Logout() {
if (clicked == false)//browser is closed
{
//window.location = "../Security/logOut.aspx";
alert('close the browser?');
var request = GetRequest();
alert('close the browser'+request );
request.open("GET", "../Security/logOut.aspx", true);
request.send();
}
}
function GetRequest() {
var xmlHttp = null;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}
catch (e) {
//Internet Explorer
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>
</head>
<body onbeforeunload="Logout()" onclick="clicked=true;">
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
 

Answers (1)