我的要求是给予访问权限,就像每个用户一次登录一样,为此,我已将登录状态更新为db(在用户登录时为db),在用户注销时为false。但是问题是当用户关闭窗口而不注销时。
为了处理窗口关闭,我实现了以下js代码
var validNavigation = false;
function wireUpEvents() {
var dont_confirm_leave = 0;
var leave_message = 'You sure you want to leave?'
function goodbye(e) {
if (!validNavigation) {
if (dont_confirm_leave!==1) {
if(!e) e = window.event;
//e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
e.returnValue = leave_message;
//e.stopPropagation works in Firefox.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
//return works for Chrome and Safari
return leave_message;
}
window.location = "logout.jsp";
}
}
window.onbeforeunload=goodbye;
// Attach the event keypress to exclude the F5 refresh
$(document).bind('keypress', function(e) {
if (e.keyCode == 116){
validNavigation = true;
}
});
// Attach the event click for all links in the page
$("a").bind("click", function() {
validNavigation = true;
});
// Attach the event submit for all forms in the page
$("form").bind("submit", function() {
validNavigation = true;
});
// Attach the event click for all inputs in the page
$("input[type=submit]").bind("click", function() {
validNavigation = true;
});
// Attach the event click for all inputs in the page
$("input[type='button']").bind("click", function() {
validNavigation = true;
});
}
// Wire up the events as soon as the DOM tree is ready
$(document).ready(function() {
wireUpEvents();
});
在这里它适用于窗口关闭,这意味着如果用户关闭窗口,它将转到注销页面,但是问题是,当用户重新加载页面时,它正要注销页面。
因此,我还需要像上述f5的js代码一样绑定reload事件,并提交和锚定标签。
在这方面,请帮助我。
提前致谢...
我想到两件事:
首先,用户已登录,这并不意味着正在进行任何活动,有些人在运行浏览器的情况下打开了PC。
其次,即使用户关闭页面,也不一定意味着他/她要注销,如果用户使用两个选项卡在您的网站上导航,则尤其如此。
因此,与其尝试检查他们何时关闭选项卡,不如考虑只在他们从其他地方登录时注销它们和/或设置一个计时器,使其在一定的不活动状态后自动注销的想法。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句