Article
Dr Design - Closing Popups and Propagating Data
This week, the Doc's in fine form, tending all kins of maladies. Here he treats SSIs, popups, and more... but if you have a question that's not covered, email him and let him know. He'll be glad to help!
Closing a Popup on Onunload
Doctor, my question is similar to Anna's, but I want the link in the content frame that loads a page to unonload a popup. There are links that open other windows on this page, and when a new window opens, I want to unonload a popup with the link.
Shuan
Shuan it's not a problem. As you are no doubt aware, a pop-up window requires a bit of javascript to get going. Here's an example of the javascript you'd have in the frameset document, which would open the pop-up when the frameset loaded.
In the following example we have the code for the frameset (frameset.html) and one of its child frames, top.html
frameset.html
<script language="javascript">
// var settings holds the settings for the popup window
var settings = "toolbar=1, scrollbars=1, location=1, status=1, menubar=1,
resizable=1, width=640, height=400";
// windowUrl holds the url for the popup window
windowUrl = "url/to/popup.html";
// now let's open the popup window.
outerName = window.open(windowUrl, 'innerName', settings);
// function closepopup will be called to close the popup
function closepopup() {
outerName.close();
}
</script>
<frameset rows="200,*">
<frame src="top.html">
<frame src="bottom.html">
</frameset>
As you can see, frameset.html will pop-up a new window. The function closepopup will close the pop-up window when it is called. Now, here's the tricky part. We are going to call the function from the child frame.
top.html
<HTML>
<HEAD>
<TITLE>TITLE>
</HEAD>
<BODY>
<a href="#" onclick="parent.closepoup()">close pop</a>
</BODY>
</HTML>
In my example (top.html) I have used an anchor and the onclick event to trigger the javascript function closepopup in the parent document, which is frameset.html.
However, you can see the principle here and apply it to your situation by calling parent.closepopup() for the onunload event of the document. You might also want to check out this handy tutorial on popup window javascript. Hope this helps!