文章作者 : linkfoxo [ webmaster@cfwindow.com ] Web URL : http://www.cfwindow.com
上载日期 : 2001-01-10
.第6节. 捕捉目前用户在线信息: logout.cfm
我现在认为以下这段代码可能各为很熟悉了. logout嘛, 删除session变量就是啦.
<HTML>
<HEAD>
<TITLE>Logout Page</TITLE>
<!-- cfheaders anti cache-->
<CFHEADER NAME="Expires" VALUE="Mon, 06 Jan 1990 00:00:01 GMT">
<CFHEADER NAME="Pragma" VALUE="no-cache">
<CFHEADER NAME="cache-control" VALUE="no-cache">
<!-- meta anti cache-->
<META HTTP-EQUIV="Expires" CONTENT="Mon, 06 Jan 1990 00:00:01 GMT">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<!-- Kills the entire key in the app variable UsersLoggedin -->
<CFOUTPUT>
<CFSCRIPT>
StructDelete(application.UsersLoggedin, #session.UserID#, true);
</CFSCRIPT>
</CFOUTPUT>
<!-- Kills the login session Variable -->
<CFSET Session.LoggedIn = FALSE>
<SCRIPT LANGUAGE="JavaScript">
self.location = 'login.cfm';
</SCRIPT>
<BODY>
</BODY>
</HTML>
现在重要的问题来啦: 像shenk先生在Cfwindow.com论坛里所问的:
"
如何检测用户关闭浏览器事件,我使用WINDOW.ONUNLOAD,但不能区别用户执行的是‘刷新’或是‘关闭’。
我在WINDOW.ONUNLOAD中检测 window.closed但不能分辨。
"
你可以用下面的代码来实验看看.它能捕捉你按F5, refresh button, 和关闭窗口的动作..
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
// Defining variables.
var refresh_clicked = 'no';
// This function is called when the user press the 'refresh Page' button.
function Refresher() {
refresh_clicked = 'yes';
location.reload();
}
</SCRIPT>
<SCRIPT FOR=window EVENT=onbeforeunload LANGUAGE="JAVASCRIPT">
// On window close , this will logout the user.
// If the user has pressed the 'Refresh Page' button, then this will be ignored.
if (refresh_clicked == 'no')
{
window.open('logout.cfm','logout_href','toolbar=no,scrollbars=no,resizable=no,width=635,height=300,menuba
r=no,location=no');
}
</SCRIPT>
</HEAD>
<BODY onKeyDown="KeyPress(window.event.keyCode);">
<INPUT TYPE="BUTTON" VALUE="Refresh Page"
onClick="if (confirm ('Are you sure? This will erase all information previously entered.'))
Refresher();">
<!-- ...(SNIP)... -->
</BODY>
</HTML>
我想你现在已经是个专家了 :) ---- linkfoxo 2001-1-10
|