Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OnClick window.close()

Status
Not open for further replies.

glendacom

MIS
Oct 23, 2002
36
US
I am trying to open/close a child window from a mother window. Here is the code in the mother window:

<html><head><body>
<a href=&quot;#top&quot; onClick=&quot;window.open('some.jpg','childWindow','dependent=0')&quot;>child is born</a>
<br>
<a href=&quot;javascript:childWindow.close();&quot;>child dies</a>
<br>
</body></head></html>

When I click &quot;child is born&quot; the window opens. When I click &quot;child dies&quot; I get an error saying that childWindow is not defined.

I'm using IE 6.0

I'm sure the problem is something obvious but it is Friday after a 60+ hour week and I'm getting to old to work such hours and I'm very tired. Any ideas?

Thanks,
Glenda
 
try window.close('childwindow')

if that doesnt work use &quot; instead of ' I can never remember when to use which one (kinda makes it hard sometimes) [soapbox]
sleep is good
 
Nope ... window.close('childwindow') simply tries to close the mother window ... window.close(&quot;childwindow&quot;) gives me a syntax error message .... anyone got any other ideas?
 
Try this, I think the problem may be that is no global declaration of a variable and then your code is running within its own &quot;function&quot; so it can't see childWindow as a variable, or even a name. To be honest I don't use popup windows, but I tested this and it works. If you need more than one window to pop, I'd suggest passing parameters to the the function.
Code:
<html>
<head>
<script>
var newWindow;
function popIt(){
newWindow=window.open('some.jpg','childWindow','dependent=0');
}
</script>
</head>
<body>
<a href=&quot;#top&quot; onClick=&quot;popIt()&quot;>child is born</a>
<br>
<a href=&quot;javascript:newWindow.close();&quot;>child dies</a>
<br>
</body></head></html>
Hope I helped / Thanks for helping
if ((x<10&&y<10) &&(((parseInt(x.toString()+y.toString())-x-y)%9)!=0)){ alert(&quot;I'm a monkey's uncle&quot;); }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top