asp中如何判断用户已经关闭浏览器?
如何判断用户已经关闭浏览器?
当用户关闭浏览器时,还要激发session_onend。
参考答案:2个办法:
一个是客户端主动发送消息告诉服务器浏览器被关了。方法:在window_unonload事件写代码“告诉”服务器。缺点:当浏览器刷新的时候该事件也会被执行!
二、服务器主动“探测”客户端有没有断线,方法:if Response.IsClientConnected then就知道客户端断线了。缺点:要不断检查客户端,耗资源。
三、用其他一些折中办法
给你一个例子看一下!
<html>
<head>
<title>用户管理</title>
<style>
.ts {font-size: 9pt }
.rs {background : FFFFEF }
.rs1 {background: DEE8C8; color:0050b0}
.th1 {background: b7e0ff; color:0050b0}
.tr1 {background:d4ebff; color:#0050b0}
.tr2 {background:f0f8ff}
.fs {font-size: 9pt; color:#0050b0}
.btn { background-color: #F3EAE9; font-size: 9pt; height: 19px; width: 40px; border-style: solid; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; cursor: hand}
.edit {
BORDER-RIGHT: #4a3163 1px solid; BORDER-TOP: #4a3163 1px solid; FONT-SIZE: 9pt; BORDER-LEFT: #4a3163 1px solid; BORDER-BOTTOM: #4a3163 1px solid; color: #003399; background-color:#F0F8FF}
a:link {COLOR: blue; FONT-FAMILY:宋体; FONT-SIZE: 9pt; TEXT-DECORATION: none}
a:visited {COLOR: blue; FONT-FAMILY: 宋体; FONT-SIZE: 9pt; TEXT-DECORATION: none}
a:hover {COLOR: red; FONT-FAMILY: 宋体; FONT-SIZE: 9pt; FONT-STYLE: normal; TEXT-DECORATION: none}
</style>
<script language="javascript">
var AddUserWin, ModifyNameWin, ModifyRightWin
var ltmAddUser, ltmModifyName, ltmModifyRight
function OnLoad() //进入该页面时最大化
{
window.moveTo(-4,-4);
window.resizeTo(window.screen.width+8,window.screen.height-20);
return true
}
function OpenAddUser(url)
{
AddUserWin=window.open(url,"","left=200,top=130,height=280,width=400,resizable=no,scrollbars=no,status=no,toolbar=no,menubar=no,location=no")
CheckAddUserWinClosed()
}
function OpenModifyName(url)
{
ModifyNameWin=window.open(url,"","left=230,top=150,height=170,width=300,resizable=no,scrollbars=no,status=no,toolbar=no,menubar=no,location=no")
CheckModifyNameWinClosed()
}
function OpenModifyRight(url)
{
ModifyRightWin=window.open(url,"","left=200,top=150,height=200,width=400,resizable=no,scrollbars=no,status=no,toolbar=no,menubar=no,location=no")
CheckModifyRightWinClosed()
}
//检查新增用户窗口是否关闭
function CheckAddUserWinClosed()
{
if (AddUserWin.closed)
{
clearTimeout(ltmAddUser)
document.location.href="userlist.asp"
}
ltmAddUser=setTimeout("CheckAddUserWinClosed()", 2000) //2秒检查一次
}
//检查修改用户名和密码的窗口是否关闭
function CheckModifyNameWinClosed()
{
if (ModifyNameWin.closed)
{
clearTimeout(ltmModifyName)
document.location.href="userlist.asp"
}
ltmModifyName=setTimeout("CheckModifyNameWinClosed()", 2000) //2秒检查一次
}
//检查修改用户权限的窗口是否关闭
function CheckModifyRightWinClosed()
{
if (ModifyRightWin.closed)
{
clearTimeout(ltmModifyRight)
document.location.href="userlist.asp"
}
ltmModifyRight=setTimeout("CheckModifyRightWinClosed()", 2000) //2秒检查一次
}
</script>
</head>
<body bgcolor="#FFFFFF" leftmargin=0 topmargin=0 class=ts OnLoad="return OnLoad()">
<table width="779" border="0" cellspacing="0" cellpadding="0" height="69">
<tr>
<td colspan="3" background="../image/wz-yhgl.JPG" height="80"></td>
</tr>
</table>
<br>
<center>
<table bgcolor=blue border=0 cellspacing=1 cellpadding=4 width=85% class=ts>
<th class=th1 colspan=4>用户总列表  <a href=javascript:OpenAddUser("createuser.asp")>增加用户</a></th>
<tr class=tr1><td align=center>用户名</td><td align=center>用户所管系统</td><td align=center>修改</td><td align=center>删除</td></tr>
<tr class=tr2><td align=center><a href=javascript:OpenModifyName("modifyuser.asp?name=11")>11</a></td><td align=center><a href=gqyhgl/index.asp?name=11>防汛工情系统</a> </td><td align=center><a href=javascript:OpenModifyRight("modifywarrant.asp?name=11")>修改</a></td><td align=center><a href=deleteuser.asp?name=11>删除</a></td></tr><tr class=tr2><td align=center><a href=javascript:OpenModifyName("modifyuser.asp?name=112")>112</a></td><td align=center><a href=gqyhgl/index.asp?name=112>防汛工情系统</a> <a href=wzyhgl/index.asp?name=112>物资调度系统</a> </td><td align=center><a href=javascript:OpenModifyRight("modifywarrant.asp?name=112")>修改</a></td><td align=center><a href=deleteuser.asp?name=112>删除</a></td></tr><tr class=tr2><td align=center><a href=javascript:OpenModifyName("modifyuser.asp?name=asdf")>asdf</a></td><td align=center><a href=gqyhgl/index.asp?name=asdf>防汛工情系统</a> <a href=wzyhgl/index.asp?name=asdf>物资调度系统</a> <a href=mediayhgl/index.asp?name=asdf>多媒体系统</a> </td><td align=center><a href=javascript:OpenModifyRight("modifywarrant.asp?name=asdf")>修改</a></td><td align=center><a href=deleteuser.asp?name=asdf>删除</a></td></tr><tr class=tr2><td align=center><a href=javascript:OpenModifyName("modifyuser.asp?name=stg2")>stg2</a></td><td align=center><a href=wzyhgl/index.asp?name=stg2>物资调度系统</a> </td><td align=center><a href=javascript:OpenModifyRight("modifywarrant.asp?name=stg2")>修改</a></td><td align=center><a href=deleteuser.asp?name=stg2>删除</a></td></tr><tr class=tr2><td align=center><a href=javascript:OpenModifyName("modifyuser.asp?name=strong1")>strong1</a></td><td align=center><a href=gqyhgl/index.asp?name=strong1>防汛工情系统</a> </td><td align=center><a href=javascript:OpenModifyRight("modifywarrant.asp?name=strong1")>修改</a></td><td align=center><a href=deleteuser.asp?name=strong1>删除</a></td></tr><tr class=tr2><td align=center><a href=javascript:OpenModifyName("modifyuser.asp?name=wer")>wer</a></td><td align=center><a href=wzyhgl/index.asp?name=wer>物资调度系统</a> </td><td align=center><a href=javascript:OpenModifyRight("modifywarrant.asp?name=wer")>修改</a></td><td align=center><a href=deleteuser.asp?name=wer>删除</a></td></tr><tr class=tr2><td align=center><a href=javascript:OpenModifyName("modifyuser.asp?name=游少爷")>游少爷</a></td><td align=center><a href=mediayhgl/index.asp?name=游少爷>多媒体系统</a> </td><td align=center><a href=javascript:OpenModifyRight("modifywarrant.asp?name=游少爷")>修改</a></td><td align=center><a href=deleteuser.asp?name=游少爷>删除</a></td></tr><tr class=tr1><td colspan=4>共有7个用户,分1页<br>[<font color=red>1</font>]</td></tr>
</table>
</center>
</body>
</html>