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.
<html> <head> <script language="JavaScript"> var lastImage,tmrImg,loopCount=1; function vwImg(img) { window.status = 'Loading Image, Please wait...'; clearTimeout(tmrImg); lastImage = new Image(); lastImage.src = img; vwImg2(); } 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) { loopCount++ window.status += '.' tmrImg = setTimeout("vwImg2();", 500) } else{ if (window.msg) { window.msg.close(); } 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.' } } </script> </head> <body> <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')"> </body> </html>
Submitted by Adam Eslinger