我使用这个 jQuery 代码来显示一个会话超时窗口 ( http://jsfiddle.net/xHEF9/515/ ) 问题是当用户在页面中停留的时间更长然后 timoutValue 时,窗口会弹出。
我需要找到一种方法来重置用户在页面上执行的每个活动的会话。
我将不胜感激。
这是我使用的代码:
<script type="text/javascript"> //<![CDATA[
var timeout=<%#(int)HttpContext.Current.Session.Timeout%>*60*1000;
//var timeout=2*60*1000;
var uservar = "<%# Session["userID"]%>";
$(window).load(function () {
(function (a) {
jQuery.sessionTimeout = function (b) {
function f(a) {
switch (a) {
case "start":
window.onbeforeunload = null;
redirTimer = setTimeout(function () {
window.location = d.redirUrl
}, d.redirAfter - d.warnAfter);
break;
case "stop":
clearTimeout(redirTimer);
break
}
}
function e(b) {
switch (b) {
case "start":
//window.onbeforeunload = null;
dialogTimer = setTimeout(function () {
a("#sessionTimeout-dialog").dialog("open");
f("start")
}, d.warnAfter);
break;
case "stop":
clearTimeout(dialogTimer);
break
}
}
var c = {
message: "Your session is about to expire.",
keepAliveUrl: "default.aspx",
redirUrl: "<%# Page.ResolveClientUrl("~/LogOut.aspx?user=")%>"+uservar,
logoutUrl: "<%# Page.ResolveClientUrl("~/LogOut.aspx?user=")%>"+uservar,
warnAfter: 9e5,
redirAfter: 12e5
};
var d = c;
if (b) {
var d = a.extend(c, b)
}
a("body").append('<div title="Session Timeout" id="sessionTimeout-dialog">' + d.message + "</div>");
a("#sessionTimeout-dialog").dialog({
autoOpen: false,
width: 400,
modal: true,
closeOnEscape: false,
open: function (b, c) {
a(".ui-dialog-titlebar-close").hide()
},
buttons: {
"Log Out Now": function () {
window.location = d.logoutUrl
},
"Stay Connected": function () {
//this event is triggered when the user tries to leave the page
window.onbeforeunload = confirmExit;
a(this).dialog("close");
a.ajax({
type: "POST",
url: d.keepAliveUrl
});
f("stop");
e("start")
}
}
});
e("start")
}
})(jQuery)
$(document).ready(function () {
$.sessionTimeout({
warnAfter: timeout-(60*1000)
,redirAfter: timeout
});
});
});//]]>
</script>