
代码
//function window.onunload() { alert('这就是你要做的事,关闭网页之后做的! '); location = 'SessionClear.aspx'; }
//function window.onbeforeunload() { alert('这就是你要做的事,关闭网页之前做的! ') }
function window.onunload() {
if ((window.screenLeft >= 10000 && window.screenTop >= 10000) || event.altKey) {
alert(window.screenLeft+","+window.screenTop);
//用户非正常关闭时需要触发的动作
location = 'Handler1.ashx';
}
}
</script>
Handler1.ashx:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.SessionState;
namespace WebApplication1
{
/// <summary>
/// $codebehindclassname$ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Handler1 : IHttpHandler,IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Session.Abandon();
context.Session.Clear();
}
public bool IsReusable
get
{
return false;
}
}