Click to See Complete Forum and Search --> : Close Window HELP


dcjones
01-10-2003, 09:49 AM
Hi all,

I have the following pages which are configured in a FRAMESET.

FRAMESET CODE:

<html>
<head>
<title>External Link</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<frameset rows="60,*" framespacing="0" marginheight="0" marginwidth="0" frameborder="0" margin="0" border="0" cols="*">
<frame src="../Admin/TOPFRAME.htm" name="top" scrolling="NO" noresize marginheight="0" marginwidth="0">
<frame src="http://www.hmce.gov.uk" name="mainFrame" marginheight="0" marginwidth="0" >
<noframes>
</noframes> </frameset>
</html>

TOP FRAME:

<html>
<head>
<title>External Link Top Frame</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="JavaScript">
<!--
function close_window() {
window.close();
}
//-->
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000" background="../images/Background.gif">
<table width="100%" border="3" bordercolor="#990000">
<tr>
<td width="68%"><img src="../images/retrun.gif" width="251" height="44" usemap="#Map" border="0"></td>
<td width="32%">
<div align="right"><img src="../images/homepage.gif" width="236" height="33" align="top"></div>
</td>
</tr>
</table>
<map name="Map">
<area shape="rect" coords="106,24,155,35" target="_parent" onMouseOver="close_window()">
</map>
</body>
</html>

BOTTOM FRAME: This is an external link

The FRAMESET works OK. But when I click on the CLOSE Gif on the TOP FRAME the window does not close.

If I run the page from the TOP FRAME as a standalone page the CLOSE works OK.

Can anyone see what is wrong with it.

REMEMBER IT IS A FRAMESET WITH 2 FRAMES:

TOP FRAME LOADS PAGE TOPFRAME.HTM AND THE BOTTOM
FRAME LOADS AN EXTERNAL LINK.

Many thanks if you can help.


Regards

Dereck

Charles
01-10-2003, 09:54 AM
Try using top.close() instead of your close_window().

pyro
01-10-2003, 10:02 AM
Or better yet, leave your close_window() function and change window.close() to top.close() in your function.

Charles
01-10-2003, 10:04 AM
Originally posted by pyro
Or better yet, leave your close_window() function and change window.close() to top.close() in your function. Why is that better? It needlessly takes up name space and garbage collection time.

pyro
01-10-2003, 10:11 AM
Originally posted by Charles
Why is that better? It needlessly takes up name space and garbage collection time. Aren't you not supposed to execute javascript commands directly from the link?

dcjones
01-10-2003, 10:12 AM
Hi Guys, now don't fall out :-)

Charles. I have amended the script to

<html>
<head>
<title>External Link Top Frame</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="JavaScript">
<!--
function top.close() {
window.close();
}
//-->
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000" background="../images/Background.gif">
<table width="100%" border="3" bordercolor="#990000">
<tr>
<td width="68%"><img src="../images/retrun.gif" width="251" height="44" usemap="#Map" border="0"></td>
<td width="32%">
<div align="right"><img src="../images/homepage.gif" width="236" height="33" align="top"></div>
</td>
</tr>
</table>
<map name="Map">
<area shape="rect" coords="106,24,155,35" href= onClick="top.close()" target="_parent">
</map>
</html>


BUT where is says - href= onClick="top.close()" target="_parent" - this statement does close the FRAMESET but tries to open - onClick="top.close()"


Any thoughts.

And thanks for your time.

Regards

Dereck

Charles
01-10-2003, 10:14 AM
Where did you hear that? And what do you think onMouseOver="close_window()" is if it's not "execut[ing] javascript commands directly from the link?

pyro
01-10-2003, 10:23 AM
I heard it from someone on these forums. I guess I should have checked into it before I said that, as I really am not sure. Sorry.

Also, dcjones this line
<area shape="rect" coords="106,24,155,35" href= onClick="top.close()" target="_parent">
has a few syntax errors, try this

<area shape="rect" coords="106,24,155,35" href="#" onClick="top.close()">

and remove your javascript from the head, or change the function name to something like function top_close() and then change the command inside the function to top.close(). Now you will just have to call your function from the link like this onClick="top_close()". Either method will work.

Oh, by the way, Charles, top_close() is calling a function, while top.close() is executing the command.

Webskater
01-10-2003, 10:30 AM
You now appear to be issuing the command "top.close()" and trying to call a function of the same name?
Why not just tell it what to do without calling a function. In your situation I use:
onclick="javascript:window.parent.close();" and it works every time.

pyro
01-10-2003, 10:31 AM
onClick="top.close()" works fine, if he removes the function named that...

dcjones
01-10-2003, 10:41 AM
Guys, it work fine following what Pyro has said.

Many thanks to you all for your help on this.

If your ever in Warwickshire England I will buy you a pint.

Thanks

Dereck