window.resizeto based on content

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 14 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
kenthompson
Posts: 14
Last visit: Tue Mar 02, 2010 3:39 am

window.resizeto based on content

Post by kenthompson »

This baffles me that I have searched for a full day all over the place and can't find the way to make this work. Surely this is a common need? All I want to do is resize my window to fit the content displayed.

I've been to MS scripting center, 4 guys from rolla... no body does anything but set size to static values

I am using VBS
I have tried everything I can find to set the height and width to.

document.body.clientheight, scrollheight,offsetHeight
and widths
document.documentelement.*

and at least a dozen other variations I have found (all javascript examples I've attempted to translate)

I've tried doing it before and after spanname.innerhtml =

I've torn my display apart trying to account for CSS divs and have it down to nothing but a body statement...

This can't really be this difficult can it?

Please Help.
User avatar
kenthompson
Posts: 14
Last visit: Tue Mar 02, 2010 3:39 am

window.resizeto based on content

Post by kenthompson »

This baffles me that I have searched for a full day all over the place and can't find the way to make this work. Surely this is a common need? All I want to do is resize my window to fit the content displayed.

I've been to MS scripting center, 4 guys from rolla... no body does anything but set size to static values

I am using VBS
I have tried everything I can find to set the height and width to.

document.body.clientheight, scrollheight,offsetHeight
and widths
document.documentelement.*

and at least a dozen other variations I have found (all javascript examples I've attempted to translate)

I've tried doing it before and after spanname.innerhtml =

I've torn my display apart trying to account for CSS divs and have it down to nothing but a body statement...

This can't really be this difficult can it?

Please Help.
User avatar
rasimmer
Posts: 182
Last visit: Fri Apr 25, 2014 7:00 am

window.resizeto based on content

Post by rasimmer »

Can you be more specific on "content displayed"? Are you saying if you only displayed an image that was 120 x 120 that the window would be resized to only 120 x 120?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

window.resizeto based on content

Post by jvierra »

What is stopping you from just setinng the size of teh spam when you add content?

I believe it looks like this: object.style.width = 99

You can add scrioll bars or use a multiline control with autoscroll and move the thumb to the bottom.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

window.resizeto based on content

Post by jvierra »

Set overflow to auto and it will produce scroll bars. A "thumb" is the thing that moves the scroll bar. The little do-hickie that moves up and down.

style="overflow: auto;"

It works on DIV and TEXTAREA but no on a SPAN. A span is a containment tag not normally used for content but to wrap other tags.

User avatar
kenthompson
Posts: 14
Last visit: Tue Mar 02, 2010 3:39 am

window.resizeto based on content

Post by kenthompson »

That's it! You gave me the key to figuring it out, jvierra. What you said and the information I've been staring at here: http://msdn.microsoft.com/en-us/library ... S.85).aspx linked together to create my solution.



On my main content column in my css I specified overflow:auto then in my resizer function I did this:

screenWidth = contentcolumn.scrollWidth + 100screenHeight = contentcolumn.scrollHeight + 200window.resizeto screenWidth,screenHeight

the added values at the end are to account for other divs in my window whose sizes are static.

It works!
thanks so much for your help!
This topic is 14 years and 4 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked