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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CLosing a window with javascript

Status
Not open for further replies.

bgreenhouse

Technical User
Feb 20, 2000
231
CA
This is a simple question. I should know how to do it, but I'm missing something obvious...I have opened a new window to display an image. I want to use an image as a button to close the window. I have tried calling a function (href=javascript:close(), with function close(){window.close}), and also just making href=javascript:window.close(), but neither seems to work. HELP!

 
The following works for me: It opens the new window and a link within that NEW window houses the onClick() that leads to the closure. If your button is on the parent window then you would need to use newWindow.close();



<HTML>
<HEAD>

<Script language=&quot;javascript&quot;>

newWindow = open(&quot;&quot; , &quot;newWin1&quot;, &quot;&quot;);
newWindow.document.open();
newWindow.document.write(&quot;<A HREF = '#' onClick='window.close();'>&quot;);
newWindow.document.write(&quot;Hello - This is 'newWin1' - Click here to close </A>&quot;);

</Script>

</HEAD>
<BODY>
</BODY>
</HTML>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top