Click here to Skip to main content
14,331,586 members
Rate this:
Please Sign up or sign in to 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

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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

///// tab close or window close //////
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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100