sizeToContent for IE

C

Csaba Gabor

Given a DOM element (such as body, but it could be a table,
form, etc.) I'd like to have IE use window.resizeBy or
window.resizeTo to resize IE to the smallest possible size
that will NOT result in overflow, or the element being 'squashed'.

My current approach is to resize the browser to
a large amount by using
window.resizeBy(window.screen.availWidth,
window.screen.availHeight)
and then halve the width at each step in a loop until either
document.body.offsetWidth-document.body.scrollWidth changes
(indicating overflow) or the .offsetHeight of the element in question
changes (which would indicate squashing).

Having established the width, I'd like to find the smallest
height, but I'm not sure of the best way. The indicator
that (I think) I'd like to use is when the scrollbar goes active,
but I don't know how to test for that. Perhaps someone could
expand on this idea, or maybe there is a flat out different approach.

Note, I am using IE as a COM object (IE 6 on Win XP Pro) so
only an IE solution is needed. Typical use will be for automatically
sizing dialogs.

Also, I'm not happy with the initial resizing because if the page
is too large to start with, the resizing might not get rid of the
overflow, but then I am still stuck with the changed window size.
Is there a fixed correlation between window.resizeTo and one
of the size measurements such as
document.body.offsetWidth and Height?

Finally, here is a simple test page:
<body>
<form method=get action='' style='border:1px solid red'>
<span id=myspan style='border:1px solid blue'>
<button id=btnOK><u>O</u>K</button>&nbsp;
<button id=btn2><u>T</u>est me</button>&nbsp;
<button><u>C</u>ancel</button></span></form>
</body>

Thanks for any tips,
Csaba Gabor from Vienna
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top