Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Close window onblur after 30 seconds

Status
Not open for further replies.

KAK

Programmer
Jul 13, 2001
9
US
I know I can close a window onBlur by:

<BODY OnBlur=&quot;window.close();&quot;>

However, how do I set a timer to only close the window if it has been onBlur for 30 seconds?

Thanks!
 
put this in you're header tags

<script>
var blurred=false;
function closer() {
if(blurred)
window.close()
}

</script>


this is you're body tag
<body onblur=&quot;blurred=true;setTimeout('closer()',3000);&quot; onfocus=&quot;blurred=false;&quot;>
 
OK, that works great! Now I need help tweaking it. When I give the focus back to the window, it still closes. Is there a way to make it not close if I give focus back to the window before the 30 seconds have elapsed?
 
Try this:
Code:
<script>
var timeoutID = null;
var timeoutSet = false;
function SetTimeout() {
   timeoutID = window.setTimeout('closer()',3000);
   timeoutSet = true;
}
function ClearTimeout() {
   if ( timeoutSet ) {
      clearTimeout(timeoutID);
      timeoutSet = false;
   }
}
</script>
...
<body onblur=&quot;SetTimeout()&quot; onfocus=&quot;ClearTimeout()&quot;>
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
I replaced the first suggestion with the second suggestion and not the window won't close at all onBlur. Please help.
 
Sorry, I got rid of the closer function when I did that too. This should be correct:
Code:
<script>
var timeoutID = null;
var timeoutSet = false;
function SetTimeout() {
   timeoutID = window.setTimeout('window.close()',3000);
   timeoutSet = true;
}
function ClearTimeout() {
   if ( timeoutSet ) {
      clearTimeout(timeoutID);
      timeoutSet = false;
   }
}
</script>
...
<body onblur=&quot;SetTimeout()&quot; onfocus=&quot;ClearTimeout()&quot;>
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top