How can i control when somebody press exit button on firefox, chrome, IE, safari or control when the presh the fan close button and then delete them from the database, actually i know that. The only problem i got is how to catch that button press.
I got some code but it doesn't seem to work. the code i got looks like this
on my default.aspx.cs
public partial class _Default : System.Web.UI.Page, System.Web.UI.ICallbackEventHandler
string callBackReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "LogOutUser", "");
string logOutUserCallBackScript = "function LogOutUserCallBack(arg, context) { " + callBackReference + "; }";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "LogOutUserCallBack", logOutUserCallBackScript, true);
void System.Web.UI.ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
_callBackStatus = "failed";
// log out the user by deleting from the LoggedInUser table
DataClassesDataContext db = new DataClassesDataContext();
var loggedInUser = (from l in db.BrugerOnlines
where l.BrugerId == Convert.ToInt32(Session["ChatUserID"])
&& l.RumId == lb
select l).SingleOrDefault();
db.BrugerOnlines.DeleteOnSubmit(loggedInUser);
db.SubmitChanges();
var besvarer = (from p in db.Rums where p.FK_Bruger == Session["SupportAdd"].ToString() select p).SingleOrDefault();
db.Rums.DeleteOnSubmit(besvarer);
db.SubmitChanges();
// insert a message that this user has logged out
this.sendbesked("Bruger har lukket siden " + DateTime.Now.ToString());
_callBackStatus = "success";
}
string System.Web.UI.ICallbackEventHandler.GetCallbackResult()
{
return _callBackStatus;
}
and on my default.aspx it looks like this.
in the javascript on the top of the page it looks like this
function LogOutUser(result, context) {
// don't do anything here
}
function LogMeOut() {
LogOutUserCallBack();
}
<div onload="SetScrollPosition()" onunload="LogMeOut()">
</div>
and the library i use is http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js and i have no idea with this code is a part of it
$(function () {
var timeout = 60000;
$(document).bind("idle.idleTimer", function () {
// function you want to fire when the user goes idle
$.timeoutDialog({ timeout: 1, countdown: 60, logout_redirect_url: 'http://www.aspdotnet-suresh.com', restart_on_yes: true });
});
$(document).bind("active.idleTimer", function () {
// function you want to fire when the user becomes active again
});
$.idleTimer(timeout);
});