Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically size popups, content=text/html

Status
Not open for further replies.

slakker

MIS
Jun 5, 2003
59
0
0
US
Hi all,

Can I javascript open a popup window and automatically size it to the contents of that page?
The problem that I see though, is that the contents of the popup page are just HTML/CSS/text without any set widths on anything at all.. they're all percentages, like my table is set to 98% width.
The only thing that might possibly provide the desired popup size, is the text width.. like I have a numbered list, that reaches a maximum char length of 200.. and I have my 98% (to provide a little bit of white space around the table border) table with a thin border around it, so the popup should be like 240pixels in width.

My environment is ASP..

Any help or thoughts would be appreciate it!
Thanks!
 
This will work in IE to expand the body's width and height to its content's size.
Code:
<SCRIPT LANGUAGE="JavaScript">
window.onload=function(){
  var maxWidth = 500;
  var maxHeight = 500;
  iHeight = document.body.scrollHeight-document.body.clientHeight;
  iWidth = document.body.scrollWidth-document.body.clientWidth;
  iHeight = iHeight > maxHeight ? maxHeight : iHeight;
  iWidth = iWidth > maxWidth ? maxWidth : iWidth;
  resizeBy(iWidth,iHeight);
}
</SCRIPT>

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
Thanks for the info guys..

adam, i'm trying to figure out how to use that script you put together. Could you please give me the syntax?

Thanks!
 
Put the code I posted in your popup and open it using the syntax rwei posted. Make sure you set the initial width and height in the window.open() to be smaller than what you expect the content to be. Like I said above, the script will expand the window to the content, but it can't shrink the window horizontally because if the window is bigger than the content, then the scrollWidth and clientWidth are always the same.

Adam
"Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done." Andy Rooney.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top