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!

Close function on popup window

Status
Not open for further replies.

mickapoo

Technical User
Jun 29, 2004
9
US
I have pop ups that are links to an enlarged image of a thumbnail. In other words, the popups are not actual html pages, they are just enlarged images. You may view my site at If you click on any of the thumbnails, you will see the popup.

Now, I know how to add a close function if this was a new html page popping up, but how can I add a close function to the popup window being that it is not an actual page? Is there something I can add to the Javascript in the <head> section that would automatically include a "close" link in the popup?

Thank you in advance.
 
Well, you can try something like this:

Code:
function popitup(url)
{
 [b]//don't send the image right away[/b]
 newwindow=window.open('about:blank', 'name', 'height=652,width=498,resizable=yes,scrollbars=no');

 [b]//NOW, open and write to the window[/b]
 newwindow.document.open();
 newwindow.document.write("<html>");
 [b]//script you are writing let's new window close
 // itself, AND return focus to the opener[/b]
 newwindow.document.write("<script>function closeMe(){var o = opener;opener=self;self.close();o.focus();}</scr"+"ipt>");
 [b]//THEN, write the image and a 'Close' link[/b]
 newwindow.document.write("<body><img src='"+url+"' />");
 newwindow.document.write("<br /><a href='javascript:void(0);' onclick='closeMe()'>Close</a>");
 newwindow.document.write("</body></html>");
 newwindow.document.close();
 return false;
}

Would something like that work for you? You might have to adjust the size of the window to show the 'Close' link, OR, you can add the call to 'closeMe()' to the onclick property of the IMG tag.

'hope that helps.

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top