How to close a javascript popupwindow when application closes

Posted by Nav234 under ASP.NET on 11/1/2010 | Points: 10 | Views : 2753 | Status : [Member] | Replies : 5
Hi all ,

I have a web application.In that through javascript i have opened a pop up window from my application.Once i close my application,the pop up window which is opened through javascript method is not getting closed.
This is my javascript
function show() {
myRef = window.open('http://www.google.com, 'mywin',
'left=20,top=20,width=700,height=600,toolbar=1,resizable=1');
}

then how to close this pop up when application is closed.

Can any 1 help on this issue ?


thanks in advance

S.Naveen...


Responses

Posted by: Varshavmane on: 11/1/2010 [Member] Starter | Points: 25

Up
0
Down
Hello,

In the form tag of your parent page you can have onunload="closeallchildwindow();" which will call javacript method:
function closeallchildwindow()
{
for(var n=0;n<children.length;n++)
{
children[n].close();
}
}

Hope that helps.

Nav234, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nav234 on: 11/1/2010 [Member] Starter | Points: 25

Up
0
Down
Hi Varshav,

I tried your same code.But when i closed the main window ,it did not call that closeallchildwindow() function called in Form tag.

So i tried in putting the same in Body tag its sometimes works sometimes when any tab change occurs,then this javascript run time error occurs when i use it in Body tag.

So what shal i do now.any other suggestions ?

Thanks in advance

S.Naveen...

Nav234, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Varshavmane on: 11/2/2010 [Member] Starter | Points: 25

Up
0
Down
What kind of error occurs? Can you please post it?

Nav234, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Nav234 on: 11/2/2010 [Member] Starter | Points: 25

Up
0
Down
Hi Varshav,

I tried your same code.But when i closed the main window ,it did not call that closeallchildwindow() function called in Form tag.

While putting the same in body tag,it works ,but if i do tab menu change ,runtime script error occurs like "run time exception occurs break,continue,ignore".

thanks in advance

S.Naveen...

Nav234, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lalji_mer on: 11/3/2010 [Member] Bronze | Points: 25

Up
0
Down
Try this code sample.

<html>
<head>
<title>JavaScript Window Close Example </title>
</head>
<SCRIPT language="JavaScript1.2">
function popuponclick()
{
my_window = window.open("",
"mywindow","status=1,width=350,height=150");
my_window.document.write('<H1>The Popup Window</H1>');
}

function closepopup()
{
if(false == my_window.closed)
{
my_window.close ();
}
else
{
alert('Window already closed!');
}
}
</SCRIPT>
<body>
<P>
<A href="javascript: popuponclick()">Open Popup Window</A>
</P>
<P>
<A href="javascript: closepopup()">Close the Popup Window</A>
</P>
</body>
</html>

more info will get here
http://www.javascript-coder.com/window-popup/javascript-window-close.phtml

LP MER

Nav234, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response