开发者

Popup box with a timer

After some specified inactivity time (IDLE Time say for 10 mins) the application should give a pop up box with a timer (should display 开发者_如何学Pythonlike 60 59 58 ....1), that box should close within 60 secs with cancel option selected and that browser should close if user doesn't select any option. If the user selects the cancel option within 60 secs also it should be closed.

To show a popup box I am using setTimeout("pop()",600000); but how to include a timer in that at least that box should close within 60 sec if user doesn't select any option. Is there a solution for this?


You may try putting below code in your popup window.

<script>
  function mytimer()
  {
    setTimeout(function closewin(){window.close;}, 600000);
  }
</script>

<body onload="mytimer();">


You can use setTimeout() or setInterval() again. In your pop() function, start another function with a timeout of 1 second (1000ms) and on each call decrease a counter and update the label. When the counter reaches 0, check that the box is still on the screen and if so call window.close() (not all browsers will actually respond to a closing attempt though).

Example:

function pop() {
  var counter = 60;

  var box = document.createElement('div');
  var label = document.createElement('span');
  label.innerText = counter;
  box.appendChild(label);

  // Position box and label as you wish.

  function tick() {
    counter--;
    if (counter == 0) {
      window.close();
    } else {
      label.innerText = counter;
      setTimeout(tick, 1000);
    }
  }

  setTimeout(tick, 1000);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜