irt.org FAQ Knowledge Base Q877
Daniel Teunkens on March 01, 2002 at 06:55:02:
It IS possible to resize the window to fit all text and images contained in it. I had this annoying customer who REALLY wanted this, so I went out and found the answer.
There is a difference between IE and Netscape (what a surprise)...
For IE, use this:
//First adjust page as much as possible to the width of any items on the page that have a fixed width (td nowrap, img, ...)
//Scroll as much to the right as possible
//Now we can find the amount of pixels the page is scrolled to the right, but beware that you don't stretch the window beyond the right edge of the screen (use Math.min). Do -24 because IE only gives the inner width of the window, and doesn't take into account the scrollbars
self.resizeBy(Math.min(document.body.scrollLeft, self.screen.availWidth - document.body.clientWidth - self.screenLeft - 24), 0)
//Now scroll down as much as possible
//Do the same thing as with the width, again make sure that you don't stretch the window beyond the bottom of your sceen
self.resizeBy(0, Math.min(document.body.scrollTop, self.screen.availHeight - document.body.clientHeight - self.screenTop - 24))
//Finish off by scrolling back to the top left of the window
For Netscape (4.8 and 6.1), use the following:
//Netscape uses different variables..., no need for -24, because self.outerWidth takes into account the complete width of the window
self.resizeBy(Math.min(self.pageXOffset, self.screen.availWidth - self.outerWidth - self.screenX), 0)
//Again different variables...
self.resizeBy(0, Math.min(self.pageYOffset, self.screen.availHeight - self.outerHeight - self.screenY))
I also tried it on Opera 6.0, but the two ways described above didn't work