faqts : Computers : Programming : Languages : JavaScript : Windows

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

3 of 8 people (38%) answered Yes
Recently 3 of 8 people (38%) answered Yes

Entry

How can I size a window to its content's size? There is an answer to this question but not for IE.

Aug 16th, 2004 08:27
Russ Locke, Guest,


function autoResizeWindow() {
  // get these values after the document has been fully opulated
  var displayWidth = window.top.document.body.offsetWidth;
  var actualWidth = document.body.scrollWidth;
  var displayHeight = window.top.document.body.offsetHeight;
  var actualHeight = document.body.scrollHeight;
  var resize = false;
  if (actualWidth > displayWidth) {
    resize = true;
    displayWidth = actualWidth;
  }
  if (actualHeight > displayHeight) {
    resize = true;
    displayHeight = actualHeight+25; // +25 for the title bar
  }
  var widthOffset = 6;
  var heightOffset = 6;
  // make sure we do not resize bigger than the screen resolution
  if (displayWidth+widthOffset > window.screen.width)
    displayWidth = window.screen.width;
  if (displayHeight+heightOffset > window.screen.height)
    displayHeight = window.screen.height;
  if (resize)
    resizeTo(displayWidth+widthOffset, displayHeight+heightOffset);
}