Click here to Skip to main content
15,064,072 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i want to call logout page on browser close or tab close i have code that is not working in Firefox,chrome only working in IE

<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()" önclick="clicked=true;">
<form id="form1" runat="server">


</form>
</body>
</html>
Posted
Updated 21-Jul-14 20:08pm
v3
Comments
   
Of course. This is because you are using unsafe ActiveXObject, proprietary to Microsoft. Don't do it. Pretty much never do it.
—SA
Member 14640376 1-Nov-19 5:17am
   
ultiultiultiultiultiultiultiultiultiultiultiultiulti
Member 14640376 1-Nov-19 5:33am
   
hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

1 solution

//// window close //////
JavaScript
$(window).unload(function() {
   your redirect page logic
});

///// tab close or window close //////
JavaScript
window.onbeforeunload = function() 
{
  your redirect page logic
}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900