none
Setting up an idle timeout

    Question

  • The code below successfully opens a new tab in IE and closes it in 60 seconds using a script in VS 2017. How would I modify this code to close the window only after 60 seconds of IDLE time (I don't want to close it obviously if someone is currently doing something in that window).

    Thanks.

    Response.Write("<script>var child = window.open( 'http://google.com', '-blank' );setTimeout(function(){child.close();}, 60000);</script>");



    • Edited by J-Bal Friday, February 09, 2018 4:12 PM
    Friday, February 09, 2018 4:09 PM

All replies

  • Hi J-Bal,

    Welcome to the MSDN forum.

    I have two solutions for your requirement.

    1. for a 3rd website, you can refer to the below code
    2. also you can host a 3rd website in your own code(iframe), so you can do your own logic by yourself.
    <script>
                var child = window.open( 'http://baidu.com', '-blank' );
                child.event.cancelBubble = false;//停止冒泡
                var isInIdle = true;
                var IdleCount = 0;
                child.onmousedown =click;
                setInterval(function(){
                    IdleCount++;
                    console.log(IdleCount);
                    if(IdleCount > 10)
                    {child.close();}}, 1000);
    
                function click(event) {
                    console.log("Click");
                    IdleCount = 0;
                }
            </script>






    Sunday, February 11, 2018 3:57 PM
    Moderator
  • I added the code (see below). I am now getting this error:

    "JavaScript runtime error: Permission denied" on the child.onmousedown = click line

    Code:

        string clickstr = "Click";
                    Response.Write("<script> " +
                    "var urlstr2 = '<%= this.urlstr1 %>'; " +
                    "var child = window.open('https://www.google.com', '-blank' ); " +
                    "var isInIdle = true; " +
                    "var IdleCount = 0; " +
                    "child.onmousedown = click; " +
                    "setInterval(function(){ " +
                        "IdleCount++; " +
                        "console.log(IdleCount); " +
                        "if (IdleCount > 10) " +
                        "{ child.close(); " +
                        "} " +
                    "}, 1000); " +
                    "function click(event) { " +
                "console.log(this.clickstr); " +
                "IdleCount = 0; } " +
                "</script >");


    • Edited by J-Bal Thursday, February 22, 2018 5:47 PM
    Thursday, February 22, 2018 5:46 PM