View Full Version : closing a popup window if it's open?
FastCougar
11-19-2004, 06:32 PM
I alert my users if their session time is running out with popup window. If the user doesn't close this window, it will stay open after the session is refreshed and also after the session expires.
For example: My sessions are set to expire after 30 minutes of inactivity. A user is surfing the site logged in and steps away from his/her desk for 25 minutes. The system throws a popup alerting them that they have been inactive for 25 minutes and will be logged out if they remain inactive for another 5 minutes. Rather than closing the popup, the user clicks on the window below and continues to use the system. I want the countdown timer to check to see if the session warning window is open and close it if it is and the timer is back above 5 minutes.
How would I check to see if a window is open and then then close it?
sad69
11-19-2004, 06:51 PM
At first glance, I think that at the end of your popup window, you could insert the following script:
...
<script>
setTimeout('window.close()', 300000);
</script>
</body>
</html>
300000 milliseconds = 5 minutes.
When you're testing it out, you can set that value lower so you're not waiting 5 minutes each time to see if it's going to work!
I think this should be okay since it's your page that's opening the popup. If the user had opened the window and navigated to your popup page, it would throw an alert asking the user if it's okay to close the window..
Hope that helps,
Sadiq.
FastCougar
11-19-2004, 06:56 PM
I need the opening page to do the closing ... having the window close itself isn't going to work for me. window 1 opens the popup, which is window 2. I need window 1's function that does the countdown clock to check if window 2 is open if the clock value is above a certain threshold (5 minutes in this case). If the window is open and the session timer is showing above 5 minutes, I need window 1 to close window 2. Since window 1 opened window 2, I would think that it should be able to close it in javascript without a problem ... I just don't know how ...
Roy Sinclair
11-19-2004, 07:13 PM
When window 1 opens the new window there is a handle to the new window's "window" object returned. Just make sure that's stored in a global object, then you can also do the setTimeout call in window 1 and when the timeout has expired check that returned value.
var popUpWindow = window.open(blah blah blah)
var aTimeoutHandle = setTimeout("closePopup();",300000);
...
function closePopup ()
{
if (popUpWindow != null) popUpWindow.close();
}
sad69
11-19-2004, 07:15 PM
I don't think I understand why window 1 has to do the closing, but this reference may be of assistance:
http://www.webreference.com/js/tutorial1/exist.html
Sadiq.
FastCougar
11-19-2004, 07:34 PM
When window 1 opens the new window there is a handle to the new window's "window" object returned. Just make sure that's stored in a global object, then you can also do the setTimeout call in window 1 and when the timeout has expired check that returned value.
var popUpWindow = window.open(blah blah blah)
var aTimeoutHandle = setTimeout("closePopup();",300000);
...
function closePopup ()
{
if (popUpWindow != null) popUpWindow.close();
}
Worked great!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.