【发布时间】:2014-05-03 01:24:38
【问题描述】:
我的页面上有一个脚本处理会话超时,当会话到期时重定向客户端的用户。完整的代码稍微复杂一些,但我已将代码精简到导致我出现问题的原因:
<head runat="server">
<script src="javascript/jquery-1.7.2.min.js" type="text/javascript">
</script>
<script type="text/javascript">
/*
Please see document ready method at the bottom that sets
up this code, calling CheckActivity() at intervals.
*/
var warningInterval, redirectTimeout;
var now = 1;
function TimeoutRedirect() {
window.location.href = "Test2.aspx";
}
//In this example this is a bit of a null op, but in real
//code this will display a warning a minute or so prior to redirect.
//This is required to recreate...
function CheckActivity() {
if (now > 4) {
clearInterval(warningInterval);
redirectTimeout = setTimeout(function () {
TimeoutRedirect(); }, 5000);
}
//Some visual activity for testing purposes.
$("#CheckActivityCount").text(now);
now++;
}
$(document).ready(function () {
warningInterval = setInterval(function () {
CheckActivity(); }, 1000);
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="CheckActivityCount">
</div>
</div>
</form>
</body>
此代码按预期工作,在(大约)十秒后重定向。但是,如果对 CheckActivity 的间隔调用完成后(5 秒后),我锁定我的屏幕,然后在重定向发生后解锁它(再过 5 秒),我的 IE 窗口中的 URL 已转到“test2” .aspx',但窗口似乎已冻结(仍显示第一页)。
这最终会解冻,但需要 10 秒才能到达下一页。
这似乎只发生在 IE(我机器上的 IE9)中,并且在 chrome 和 firefox(奇怪的是 IE6)中很好。
(Test2.aspx是一个很简单的页面,只包含'success'的文字。)
请注意,如果我将重定向从 test.aspx 更改为 http://www.google.com/,这似乎不是问题。但是,如果我将 test2.aspx 更改为绝对 URL(唯一的主要区别是这将是 localhost 地址),仍然不起作用。
【问题讨论】:
-
变量'redirectTimeout'是否声明在任何地方?由于它的工作奇怪尝试清除redirectTimeout。只是在黑暗中开枪;D。
-
对不起,redirectTimeout 应该在那里。
-
window.location.replace("Test2.aspx");或window.navigate("Test2.aspx");或self.location=Test2.aspx你试过这些,这些也冻结了吗? -
@03Usr - 这三个都没有对结果产生影响。
-
@Paddy - 我现在在 IE10 中遇到同样的问题。你最终找到解决方案了吗?下面标记的答案对我不起作用。在计算机被锁定时,JavaScript 事件似乎仍在按时执行....但是窗口还没有重新绘制。我发现的另一件事是,如果您在冻结的屏幕上用鼠标快速单击大约 3-5 次,它几乎会立即重新绘制……而不是等待 10 秒。对我来说,它确实已经重定向到新的 URL.... 只是没有重新绘制屏幕来显示这个。
标签: javascript internet-explorer