hpriya78
asked on
Capuring close event of Popup window.
I have a pop-up window that keeps refreshing every 10 seconds.If it finds that its opener has been closed ..it goes to the logout page and logs out the user.I have accomplished this task.If the user will closes the opener window, then the user is automatically logged out.
Now,if the user closes the pop-up window and then the opener window,I have no control.
What I want to accomplish is this: If the user closes the pop-up window while its opener is still present ,the user must be logged out.I need to capture the close event correctly for this.My problem is if I put the redirection to the logout page on the window's unload event,it is a problem ..as the unload event gets triggered even when the page is being refreshed.and this pop-up is refreshed every 10 seconds!!
Restriction : I can't change all pages of my application..that is why a pop-up window is opened when the user logs in and it keeps track of the user closing the opening window.
I have a good link on controlling windows using Javascript ..but am still unable to do this.The link is this : http://developer.irt.org/script/window.htm.
Any help/sugestion will be welcome.
Now,if the user closes the pop-up window and then the opener window,I have no control.
What I want to accomplish is this: If the user closes the pop-up window while its opener is still present ,the user must be logged out.I need to capture the close event correctly for this.My problem is if I put the redirection to the logout page on the window's unload event,it is a problem ..as the unload event gets triggered even when the page is being refreshed.and this pop-up is refreshed every 10 seconds!!
Restriction : I can't change all pages of my application..that is why a pop-up window is opened when the user logs in and it keeps track of the user closing the opening window.
I have a good link on controlling windows using Javascript ..but am still unable to do this.The link is this : http://developer.irt.org/script/window.htm.
Any help/sugestion will be welcome.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hi KnightEKnight,
I have already accomplished what u have said as I mentioned in my query.What I actually need is a method by which I can capture the close event of the popp-up window.My main application runs in the main large window.I have a popup window that checks for the existence of the main window..if the main window is closed ..it automatically logs off the user.This is fine and working..now waht I require is a method by which I can prevent/control the closing of the pop-up window.
Hi alambares ..I have tried it ..doen't work..am I doing something wrong? here is a copy of my pages..
My IE browser version is 6.0.2800.1106 with SP1..I need to make this work only for IE6 and above as this is going to be used only internally.
//Main Page Script that calls the pop-up
<script>
childwin=window.open("test 1.asp", "test1", "width=100, height=100, left=0, top=0,menubar=no, status=no, location=no, toolbar=no, scrollbars=no, resizable=no");
self.focus();
</script>
//Popup page
<html>
<head>
<script>
<!--
var limit="0:10"
var bReloading=false
if (document.images){
var parselimit=limit.split(":" )
parselimit=parselimit[0]*6 0+parselim it[1]*1
}
function beginrefresh()
{
bReloading = true;
if (!document.images)
return
if (parselimit==1)
{
window.location.reload()
}
else
{
parselimit-=1
curmin=Math.floor(parselim it/60)
cursec=parselimit%60
if (curmin!=0)
curtime=curmin+" minutes and "+cursec+" seconds left until page refresh!"
else
curtime=cursec+" seconds left until page refresh!"
window.status=curtime
setTimeout("beginrefresh() ",2000)
if (window.opener.closed)
{
redirURL = "logout.asp";
self.location.href = redirURL
}
}
}
function closewin()
{
//alert("hi")
window.open("logout.asp"," logout","" )
}
window.onload=beginrefresh
//alert(top.opener.closed)
//-->
</script>
</HEAD>
<BODY onunload="if (!bReloading){closewin();} ">
<img src="images/midd1.jpg" width="86" height="95">
<p>
</BODY>
</HTML>
I have already accomplished what u have said as I mentioned in my query.What I actually need is a method by which I can capture the close event of the popp-up window.My main application runs in the main large window.I have a popup window that checks for the existence of the main window..if the main window is closed ..it automatically logs off the user.This is fine and working..now waht I require is a method by which I can prevent/control the closing of the pop-up window.
Hi alambares ..I have tried it ..doen't work..am I doing something wrong? here is a copy of my pages..
My IE browser version is 6.0.2800.1106 with SP1..I need to make this work only for IE6 and above as this is going to be used only internally.
//Main Page Script that calls the pop-up
<script>
childwin=window.open("test
self.focus();
</script>
//Popup page
<html>
<head>
<script>
<!--
var limit="0:10"
var bReloading=false
if (document.images){
var parselimit=limit.split(":"
parselimit=parselimit[0]*6
}
function beginrefresh()
{
bReloading = true;
if (!document.images)
return
if (parselimit==1)
{
window.location.reload()
}
else
{
parselimit-=1
curmin=Math.floor(parselim
cursec=parselimit%60
if (curmin!=0)
curtime=curmin+" minutes and "+cursec+" seconds left until page refresh!"
else
curtime=cursec+" seconds left until page refresh!"
window.status=curtime
setTimeout("beginrefresh()
if (window.opener.closed)
{
redirURL = "logout.asp";
self.location.href = redirURL
}
}
}
function closewin()
{
//alert("hi")
window.open("logout.asp","
}
window.onload=beginrefresh
//alert(top.opener.closed)
//-->
</script>
</HEAD>
<BODY onunload="if (!bReloading){closewin();}
<img src="images/midd1.jpg" width="86" height="95">
<p>
</BODY>
</HTML>
Hi, hpriya78,
I might be wrong, but I think that in your page bReloading is always 'true', because on the page onload event you call the beginrefresh() function, which sets bReloading to 'true'.
Instead you should have sth. like:
bReloading = false;
function beginrefresh(){
bReloading = true;
window.location.reload()
}
function init(){
curmin=Math.floor(parselim it/60)
cursec=parselimit%60
if (curmin!=0)
curtime=curmin+" minutes and "+cursec+" seconds left until page refresh!"
else
curtime=cursec+" seconds left until page refresh!"
window.status=curtime
setTimeout("beginrefresh() ",2000)
if (window.opener.closed)
{
redirURL = "logout.asp";
self.location.href = redirURL
}
}
window.onload=init
The init() function will be called on the onload window event, setting the window timeout, and the beginrefresh() function will handle the page reload when the timeout expires.
Ileana.
I might be wrong, but I think that in your page bReloading is always 'true', because on the page onload event you call the beginrefresh() function, which sets bReloading to 'true'.
Instead you should have sth. like:
bReloading = false;
function beginrefresh(){
bReloading = true;
window.location.reload()
}
function init(){
curmin=Math.floor(parselim
cursec=parselimit%60
if (curmin!=0)
curtime=curmin+" minutes and "+cursec+" seconds left until page refresh!"
else
curtime=cursec+" seconds left until page refresh!"
window.status=curtime
setTimeout("beginrefresh()
if (window.opener.closed)
{
redirURL = "logout.asp";
self.location.href = redirURL
}
}
window.onload=init
The init() function will be called on the onload window event, setting the window timeout, and the beginrefresh() function will handle the page reload when the timeout expires.
Ileana.
ASKER
Well,I got a great script that will help me detect the close event of my popup window.
if(window.screenTop>10000)
{
if (!window.opener.closed)
{
window.opener.location="lo gout.asp"
}
else
{
window.open("logout.asp"," logout","" )
}
}
Well, I got this from a a site.And since I borrowed code from alambres i'll accept it as I am using some part of his code although that does not provide a complete solution.
Ilearnarc: I am not sure about this ..I haven't tried it ..I have used the bReloading part exaclty as specified by alambres..perhaps u could ask alambres.
if(window.screenTop>10000)
{
if (!window.opener.closed)
{
window.opener.location="lo
}
else
{
window.open("logout.asp","
}
}
Well, I got this from a a site.And since I borrowed code from alambres i'll accept it as I am using some part of his code although that does not provide a complete solution.
Ilearnarc: I am not sure about this ..I haven't tried it ..I have used the bReloading part exaclty as specified by alambres..perhaps u could ask alambres.
<SCRIPT>
var mypopup; // global to hold the popup handle
// later, when you open the popup:
mypopup = window.open( url, "mypopup", "width=800,height=600" );
// then every 10 seconds poll to see if the popup still exists, if it doesn't, then redirect to logout:
setInterval( "if(!mypopup || mypopup.closed==true)locat