我如何控制当有人按下 firefox、chrome、IE、safari 上的退出按钮或控制何时按下风扇关闭按钮然后从数据库中删除它们,实际上我知道。我遇到的唯一问题是如何抓住按钮按下。
我得到了一些代码,但它似乎不起作用。我得到的代码看起来像这样
在我的 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;
}
在我的 default.aspx 上,它看起来像这样。
在页面顶部的 javascript 中,它看起来像这样
function LogOutUser(result, context) {
// don't do anything here
}
function LogMeOut() {
LogOutUserCallBack();
}
<div onload="SetScrollPosition()" onunload="LogMeOut()">
</div>
我使用的库是http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js 我不知道这段代码是它的一部分
$(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);
});