8

The Problem

Occurs on IE10. (IE8 works fine.)

I've written some JavaScript code that, after 20 minutes of inactivity, redirects the browser to another URL to indicate the user was logged out. Normally this works fine. However I've noticed a strange scenario.... if the user's Windows computer was locked during this timeout then it appears as though nothing has happened.

However, when I look at the browser's URL bar, I can clearly see that the URL has already been updated to the auto-logout page. But the entire content of the browser window is still displaying the old page!!!! For some reason, the browser window has not repainted / refreshed. It looked like it had frozen.

At this point... if I rapidly mouse click around on the page then the browser "wakes up" and shows the new content. (It seems that just one mouse click is not enough. The more rapidly you click around, the faster it "wakes up".)

Theory

My best guess is the IE10 browser stops repainting the window while the computer is locked. However, I do believe the JavaScript engine is still running though, because I tested another scenario with multiple JS new Date() time stamps at various intervals and when the screen finally repainted, each date time was unique, showing the time it actually occurred.

Recreating the Issue - version 1

  1. Launch the JavaScript code below in IE10
  2. Lock my Windows computer before 10 seconds has elapsed.
  3. Wait 10 seconds, and then unlock my computer.
  4. See the IE10 window has failed to repaint.

I did notice this only occurs when redirecting to a URL on our company's local intranet. I have no idea why this is the case.... but if I have the URL as Google or Yahoo's home page.... then I cannot recreate the issue. It just works correctly. Made me wonder if it could be a Group Policy / Trusted Zones / Intranet vs Internet issue of some sort...

<!DOCTYPE HTML>
<html>
<head></head>
<body>    
<script>
    var url = 'http://IntranetWebApps.OurCompany.com/MyWebApp/Home';  // fails
    //url = 'http://www.yahoo.com';  // this 'Internet' site works
    //url = 'http://www.google.com';  // this 'Internet' site works 

    setTimeout(function () { 
            window.location.href = url;
        }, 10000  // wait 10 seconds, then execute redirect
    );
</script>
</body>
</html>

Question

Does anyone have any ideas how to solve this issue, so that the IE10 window will always repaint instantly instead of displaying stale content?

Jason Parker
  • 4,960
  • 4
  • 41
  • 52
  • Yes, I have seen this question: http://stackoverflow.com/questions/11578267/javascript-settimeout-and-redirect-ie-freezes However, I am expanding the question to a larger issue. It is not even specifically related to doing a JavaScript redirect.... although this is ONE way to recreate the problem. – Jason Parker Mar 04 '14 at 23:03
  • 2
    As an idea, if you don't get any help here, you might want to repost your incredibly well written question over on Code Review. – krillgar Apr 27 '14 at 19:39

2 Answers2

4

Finally found a way to overcome this ridiculous annoyance. I added some JavaScript to my auto-logout landing page (where I was redirecting the users). This JavaScript updates the page content every one second.

Voila!

The real issue here is that even if the IE10 window content was legitimately updated and ought to repaint (such as when a redirect occurs) while the computer was locked..... it will not repaint.

IE10 only repaints if the page content update action occurs WHILE the computer is unlocked.

The JavaScript below updates the page content every one second, by setting the DIV's content to the current time, including seconds. This means if the user locks their computer and goes to lunch for an hour, their browser page will be timed out and redirected to the logout page while they are gone. When the user comes back and unlocks their computer... they will see the old stale content for 1 second.... and then the running JavaScript forces a repaint, and they will quickly see the logout screen's content.

<h1>Due to inactivity, you were automatically logged out.  (Deal with it.)</h1>
<div id="div1" style="background-color: white; color: white;">
</div>
<script>
    (function ()
    {
        var forceRepaint = function ()
        {
            var myDiv = document.getElementById("div1");
            myDiv.innerHTML = new Date().toLocaleTimeString();
        };
        setInterval(forceRepaint, 1000);
    })();
</script>

I did try things like just setting the visibility on the DIV to make it hidden (instead of setting white background and white text color), but the browser will not repaint. It's very intelligent about detecting if a visible change has really occurred.

BONUS -- Yahoo/Google versus my Logout page

The reason I could not create the issue when redirecting to external sites like Yahoo or Google was that they probably had some JavaScript code running that would indeed update their page's content after it had loaded. They essentially had more 'stuff' going on. Whereas my original logout page was very plain and did not have any JavaScript code executing on page load.

Jason Parker
  • 4,960
  • 4
  • 41
  • 52
  • Great solution, I gave you a +1 for it! **N.B.** This script shows the time continuously, for those who want to stop it after a while - see [here.](http://stackoverflow.com/a/109091/1016343) After the line `myDiv.InnerHTML...` you can add `clearInterval(forceRepaint);` and you can use a style white-on-white `color: #FFFFFF; background-color: #FFFFFF;` to make the time invisible - this will force to repaint, as you write, hiding the div does not do it. – Matt Dec 01 '15 at 09:34
2

I suspect this might be specific to particular set of graphics cards or drivers. From the IE menu bar, select Internet Options. On the advanced tab, select the "Use software rendering" option. Then reboot.

selbie
  • 100,020
  • 15
  • 103
  • 173
  • Thanks! Your idea does resolve the issue I described. I am amazed that you somehow knew my issue was related to software vs hardware rendering. Unfortunately, I wouldn't have been able to use this as a solution because I can't go and make that settings change to every user's computer. But I'm still glad you were able to shed some light on the source of the problem. I figured out a solution today that only requires adding JavaScript to the auto-logout landing page, so I am posting that as the answer. – Jason Parker Apr 30 '14 at 22:17