Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / JScript / October 2003

Tip: Looking for answers? Try searching our database.

Closing Popup window when Parent Window is closed

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nithi Gurusamy - 20 Oct 2003 21:57 GMT
Dear Group:

Is there a way to keep track of  a popup window and close it when the parent
window is closed?

I want to get the window object by passing the name of the window. Is it
possible in Javascript?
Or is there a way to store the window object as cookie and retrieve it
later.

Thanks
Nithi Gurusamy
Joe Fawcett - 21 Oct 2003 10:45 GMT
> Dear Group:
>
[quoted text clipped - 8 lines]
> Thanks
> Nithi Gurusamy

The return value of window.open gives you the pointer to the new window.

Signature

Joe

Nithi Gurusamy - 21 Oct 2003 15:20 GMT
I am not talking about that. That is easy to do. This is a different
situation. After opening the popup, the URL of the parent window changes. So
the new window pointer will be lost. Is there a way to save the window
pointer in a global location or is it possible to retireve the popup
window's reference later by using the "window name"?

Hope you follow what I explained.

Thanks
Nithi Gurusamy

> > Dear Group:
> >
[quoted text clipped - 11 lines]
> >
> The return value of window.open gives you the pointer to the new window.
Walter Zackery - 21 Oct 2003 15:41 GMT
You can retrieve a reference to a window knowing only its name. The only
hitch to this is the possibility of more than one window (and/or frame)
currently open with the same name. In that case, one window or frame will be
referenced, but you have no control over which one.

var win = window.open("","popupWindow");

| I am not talking about that. That is easy to do. This is a different
| situation. After opening the popup, the URL of the parent window changes. So
[quoted text clipped - 22 lines]
| > >
| > The return value of window.open gives you the pointer to the new window.
Nithi Gurusamy - 21 Oct 2003 15:48 GMT
Dear Group:

I unknow we can use onunload events of window and body objects to detect
when the URL changes. But is there a event that tells me the Internet
Explorer or Netscape window itself is closing?

Thanks
Nithi Gurusamy
Raffaele Rialdi [MVP] - 21 Oct 2003 20:28 GMT
> [...] But is there a event that tells me the Internet
> Explorer or Netscape window itself is closing?

No you have to detect by yourself what caused the page to be unloaded.
Look at the sample below

If you are thinking to use the unload event to do something (free resource
for example) on the server, you are going in the wrong direction.
Http is a disconnected protocol and you should never rely on what's
happening on the client. Client can cut the wire, crash the system, kill the
browser and this should not cause any problem on your server.
You should use Session_End event instead that will happen after 20min
(default) from the last request.

Signature

Raffaele Rialdi
Microsoft .NET MVP http://mvp.support.microsoft.com
UGIdotNET - User Group Italiano .NET  http://www.ugidotnet.org

<HTML>
<HEAD>
<SCRIPT>
var ctlClicked

function Load()
{
ctlClicked = false;
alert("evento onLoad");
}

function GoingAway()
{
if(ctlClicked == false)
 alert("Maybe you are closing the browser");
}

function ctlclicked()
{
if(event.srcElement.tagName == "A")
{
 ctlClicked = true
 alert("evento onclick dal controllo '" + window.event.srcElement.id +
"'");
}
}

function DivClick()
{
alert(window.event.srcElement.parentElement.nextSibling.id);
var Elem = window.event.srcElement.parentElement.children(1);
if(Elem.style.display == "none")
{
 Elem.style.display = "";
}
else
{
 Elem.style.display = "none";
}

}
function DivOver()
{
window.event.srcElement.style.cursor='hand';
}
function DivOut()
{
window.event.srcElement.style.cursor='auto';
}

</SCRIPT>
</HEAD>

<BODY onload="Load()" onclick="ctlclicked()" onbeforeunload="GoingAway()"
language=javascript>

<h1>Hello, world</h1>
<h3>by Raffaele Rialdi, esempio postato su ugidotnet</h3>

<a id=myLink href=http://www.ugidotnet.org>Questo ? un link</a>

<Div>
<div language=javascript OnClick="return DivClick();" onmouseover="return
DivOver();" onmouseout="return DivOut();"> Titolo</div>
<div>Hello, world!</div>
</Div>
<div id=shad>shadow</div>

</BODY>
</HTML

Gonzalo Arin - 23 Oct 2003 03:22 GMT
If you opened the pop up window giving it a name, you should be able to
close it placing an onunload event handler in the body tag of the parent
window.

Gonzalo.

> Dear Group:
>
[quoted text clipped - 8 lines]
> Thanks
> Nithi Gurusamy

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.