Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap

Q1782 Q475 Is it possible to pop-up a window the same size as the image it contains?

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

Pre-load the image to find it's width and height, then create the window with those parameters.

<script language="JavaScript">
var lastImage,tmrImg,loopCount=1;

function vwImg(img) {
  window.status = 'Loading Image, Please wait...';
  lastImage = new Image();
  lastImage.src = img;

function vwImg2() {
  if (loopCount%30==0) {
    if (!confirm('This image is having trouble loading. Continue to wait?')) {
      window.status = 'Cancelled.';
      return false;
  if (!lastImage.complete) {
    window.status += '.'
    tmrImg = setTimeout("vwImg2();", 500)
  } else{
    if (window.msg) {
    msg = window.open('','msg','width='+lastImage.width+',height='+lastImage.height+',resizable,scrollbars=no');
    msg.document.write('<html><body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0><img src="'+lastImage.src+'"></body></html>');
    window.status = 'Done.'


<input type="button" value="1" onclick="vwImg('1.gif')">
<input type="button" value="2" onclick="vwImg('2.jpg')">
<input type="button" value="3" onclick="vwImg('3.jpg')">


Submitted by Adam Eslinger

©2018 Martin Webb