Closing a popup window from a child frame in Firefox

I have a close window link in a popup pages that consists of 2 frames. To close the popup, I can’t use window.close(), because that will only close the frame and not the entire popup.

Using top.window.close() works perfectly for IE, but doesn’t work at all in Firefox.

Anyone have an idea of what code you can use to close a popup from a nested from that works across all browsers?

Thanks in advance,

Dave.

You might try switching focus to the top before implementing the close, like top.focus();self.close(); You might also try just using top.close(), since using window in there is actually a bit redundant.

JVLB: Thanks for the suggestions, I tried them both but unfortunately the popup will still not close in Firefox.

Any other ideas?

If you assign the window to a variable upon opening, as in:

var winOne=window.open(“”,“”,“”);

It should be possible to close it with:

winOne.close();

top.close() works fine in all flavors of moz, just tested it.

How are you calling it?

Adios: I’m using the following link tag around a close button:

<a href=“JavaScript://” onClick=“javascript:top.close();return false;”><img src=“…/images/buttons/close.gif” alt=“Close this Preview” width=“51” height=“23” border=“0”></a>

Dave.

A few changes - none earth-shattering - but, still works. Here:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>untitled</title>
</head>
<body>
<a href="#" onclick="window.open('frameset.html','','status=0,width=500,height=400');return false;">open</a>
</body>
</html>

[frameset.html]


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>untitled</title>
<script type="text/javascript">

function foo()
{
	return '<body><a href="#null" onclick="top.close();return false;">' +
	'<img src="http://www.sitepoint.com/forums/images/smilies/hert.gif" border="0"> close</a></body>';
}

</script>
</head>
<frameset rows="50%,*">
<frame src="javascript:'top'">
<frameset cols="50%,*">
<frame src="javascript:'left'">
<frame src="javascript:top.foo()">
</frameset>
</frameset>
</html>

[…if these edit boxes get any smaller I’m gonna ask for a refund…]

Works even with a nested frameset.