Auto Resize Browser Window To Image Size

This script is typically best for pop-up windows where you want to display random images on request. It will allow browser window to auto-fit according to the image size.

Add this script into head section of web page:

<script language="javascript">
var i=0;
function resize() {
  if (navigator.appName == 'Netscape') i=40;
  if (document.images[0]) window.resizeTo(document.images[0].width +30, document.images[0].height+80-i);

We just wrote a function named as resize. Call this function in the body tag of the popup page.

<body onload="resize();">

This function will serve the purpose and on page load it will look for the image size and will resize the browser window according to the image size.

This script is for popup page at which image is placed. Call the popup page with no toolbar or menubar as decsribed below:

<a href="#" onClick="'popup-page.html', '', 'toolbar=0,menubar=0,location=0,left=0,top=113,screenX=0,screenY=100,scrollbars=yes'); return false;">Launch popup</a>

Download Window Resize Script