Had a question regarding logging out users who don't click Logout, who instead just close the browser.
I have two scripts pretty much the same but they only work in IE due to that fact that onbeforeunload was implemented for IE.
The latest version;
Is there any method or way to get this to work in Firefox?PHP Code:
window.onbeforeunload = confirmExit;
var aClick=false;
function confirmExit(e){
if(document.all)e = event;
if(!e)e=window.event;
if(e){
if(aClick==false && (e.target==document || e.clientX<0 || e.clientY<0)) {
//alert("Logging out...");
// Add server call to logout the user
/* Original code commented out because of page refresh, page reloads or form submits.
alert('about to open the window');
ajaxCall("http://example.com/logout.php");
*/
//adding this allows for page refresh, page reloads or form submits in IE only
function open_win() {
ajaxCall("http://example.com/logout.php");
}
open_win()
}
}
}
function ajaxCall(dname){
var xmlDoc;
if (window.XMLHttpRequest){
xmlDoc = new window.XMLHttpRequest();
xmlDoc.open("GET", dname, false);
xmlDoc.send("");
//alert(xmlDoc.responseText); //Hide blank alert boxes.
//return xmlDoc.responseXML; //Comment out - not needed.
// IE 5 and IE 6
}else if (ActiveXObject("Microsoft.XMLDOM")){
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = false;
xmlDoc.load(dname);
//alert(xmlDoc.responseText); //Hide blank alert boxes.
//return xmlDoc; //Comment out - not needed.
}
//alert("Error loading document"); //Hide blank alert boxes.
return null;
}
If Yes, how?
Bookmarks