Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Scrollbars not being taken into account with JavaScript

0 views
Skip to first unread message

Nathan Sokalski

unread,
Feb 8, 2008, 1:40:56 PM2/8/08
to
I am using the following function to set the size of a <div> on my page:

function
SetTitleWidth(){document.getElementById('divTitle').style.width=(window.innerWidth+window.pageXOffset)+'px';}

However, this does not take the scrollbars into account, therefore always
leaving a small amount of space left to scroll, which causes the page to be
pretty much an infinite width. If the scrollbars are not there, everything
works fine. If I understand correctly, this is not the way things are
supposed to work. Isn't window.innerWidth supposed to be the width of the
visible content area WITHOUT including the scrollbars? What can I do about
this?
--
Nathan Sokalski
njsok...@hotmail.com
http://www.nathansokalski.com/


Pász Gergely

unread,
Feb 9, 2008, 2:43:56 AM2/9/08
to
Nathan Sokalski wrote:
> I am using the following function to set the size of a <div> on my page:
>
> function
> SetTitleWidth(){document.getElementById('divTitle').style.width=(window.innerWidth+window.pageXOffset)+'px';}
>
> However, this does not take the scrollbars into account, therefore always
> leaving a small amount of space left to scroll, which causes the page to be
> pretty much an infinite width. If the scrollbars are not there, everything
> works fine. If I understand correctly, this is not the way things are
> supposed to work. Isn't window.innerWidth supposed to be the width of the
> visible content area WITHOUT including the scrollbars? What can I do about
> this?

http://developer.mozilla.org/en/docs/DOM:window.innerWidth

I think you could detect if the window's width differs from the
document's (or if the document's is greater).

Nathan Sokalski

unread,
Feb 9, 2008, 11:58:59 PM2/9/08
to
First of all, the value that I ultimately want to know is the width of the
document. If you look at the code I included in my original posting, it does
not necessarily calculate the width of the document, it calculates the x
coordinate of the right side of the browser viewport relative to the left
side of the document. Since there is no way that I know of that works in all
browsers to calculate the document width, my problem right now is with
Firefox's window.innerWidth including the scrollbars in the returned value.

"Pász Gergely" <past...@gmail.com> wrote in message
news:lt6dnYiN6L8vxDDa...@mozilla.org...

0 new messages