tags:

views:

49

answers:

3

hi, After some specified inactivity time (IDLE Time say for 10 mins) the application should give a pop up box with a timer (should display like 60 59 58 ....1), that box should close within 60 secs with cancel option selected and that browser should close if user didint select any option .If the user selects cancel options within 60 secs also it should be closed

To appear a pop box i am using setTimeout("pop()",600000); but how to include timer in that atleast that box should close within 60 sec if user doesnt select any option Is there any solution is there Plz help Thanks in Advance, Satya

A: 

You may try putting below code in your popup window.

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

<body onload="mytimer();">
Sarfraz
+1  A: 

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);
}
Max Shawabkeh
hi Max,Thanks for ur valuable suggestionbut I need to close the box automatically without any confirmation even that window.close will ask the confirmation.So is there any alternative way to create
Satya
I'm somewhat confused - do you want to close the popup or the whole page? You can't close the whole browser window reliably without confirmation. There're some hacks like setting `window.opener` to a random string but that will most likely fail on some browsers.
Max Shawabkeh
My application is with basic authentication so in that session is not invalidating without closing window.So if my application is idle for 10 mins then by using setTimeout() giving alert with confirm box ,if i press it OK its reloading the page CANCEL means i am redirecting the page to JSP page where in that page LOGIN option is there as i am not closing the browser so it is not asking LOGIN credentials (Basic Authentication is used).So i need a sol such that it should asks Login or confirm box wid timer so that i need to close that window after 60 sec if i didnt press any thing ok or cancel
Satya
A: 

window.close(); again will ask for confirmation, how can we prevent this?

jee