Javascript setTimeout和重定向 - IE冻结

Pad*_*ddy 8 javascript internet-explorer

我的页面上有一个处理会话超时的脚本,当会话到期时在客户端重定向用户.完整的代码有点复杂,但我已经将代码修改为导致我问题的原因:

<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>
Run Code Online (Sandbox Code Playgroud)

此代码按预期工作,在(大约)十秒后重定向.但是,如果间隔调用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(唯一的主要区别是这将是本地主机地址)仍然无效.

Cle*_*ud8 4

我遇到了同样类型的问题,所以我创建了一个不同的问题,这样我就可以专注于我认为问题的核心。(当计算机处于锁定屏幕时,IE 不会重新绘制。)

不管怎样,我终于找到了解决这个问题的方法。你可以在这里看到我的回答。本质上,您可以通过在自动注销目标页面中放入一些 JavaScript 来定期更新页面内容来解决您的问题......这将迫使 IE 重新绘制页面。

这样,我可以在当前页面上的会话到期之前执行我想要的任何自动保存逻辑,然后将它们踢到自动注销页面。