Javascript,auto refresh
<p>i currently am using the below javascript code below, </p>

<pre><code>   &lt;script type="text/javascript"&gt;
        function PrintWindow()
        {                     
            window.print();            
            CheckWindowState(); 
        }

        function CheckWindowState()
        {            
            if(document.readyState=="complete")
            {
                window.close();  
            }
            else
            {            
                setTimeout("CheckWindowState()", 2000)
            }
        }    

        PrintWindow();
        //window.onfocus = function() { window.close(); }

        // Trying to auto refresh the page after 3 seconds of no use.
        function setIdle(cb, seconds) {
            var timer; 
            var interval = seconds * 1000;
            function refresh() {
                clearInterval(timer);
                timer = setTimeout(cb, interval);
            };
            $(document).on('keypress, click', refresh);
            refresh();
        }

        setIdle(function() {
            location.href = location.href;
        }, 3);



    &lt;/script&gt;
</code></pre>

<p>My original question was how to go home when the print box was finished but was told this was impossible, so i am now wondering how to auto refresh the page after so many seconds have passed, i have added in code to do this but it is not working</p>

<p>i have now managed to fix it, if any one is wondering :</p>

<p>var timer = null;</p>

<pre><code>function goAway() {
    clearTimeout(timer);
    timer = setTimeout(function() {
        window.location = 'http://localhost:8080/fileuploadWithPreview';
    }, 5);
}

window.addEventListener('mousemove', goAway, true);

goAway();  // start the first timer off
</code></pre>

<p>This when the window is closed takes me to the home page so it is possible to do</p>
