Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1443 How else can I pop-up a window the same size as the image it contains?

You are here: irt.org | FAQ | JavaScript | Window | Q1443 [ previous next ]

It is usually difficult to avoid the margins browsers will automatically place around your image. If you know the size of the image you wish to place in your pop-up window, the alternative to using the <IMG src="">-tag is using the <BODY background>-tag. Open a window with the size of your image, and create a html-document on-the-fly with the image as a background.

Place this function inside the <HEAD> section of your page:

<script language="JavaScript">
function picture(picgoal,picname) {
  PicWin=window.open("",picname,'status=0,scrollbars=0,resizable=0,width=100,height=100,screenX=50,screenY=50,top=50,left=50');
  PicWin.document.open();
  PicWin.document.writeln('<html>');
  PicWin.document.writeln('<head>');
  PicWin.document.writeln('<title>Picture in a window</title>');
  PicWin.document.writeln('</head>');
  PicWin.document.writeln('<body background="'+picgoal+'">');
  PicWin.document.writeln('</body>');
  PicWin.document.writeln('</html>');
  PicWin.document.close();
}
</script>

Then this as the link:

<A HREF="http://www.picture.gif" onClick="picture(this,'picturewindow'); return false">Click here</A>

Submitted by Eric Rietzschel

©2018 Martin Webb