Skip to main content

Bug Tracker

Side navigation

#8048 closed bug (patchwelcome)

Opened January 25, 2011 10:27AM UTC

Closed January 26, 2011 03:57PM UTC

Last modified October 14, 2012 01:14PM UTC

overflow:scroll gives wrong width in IE8

Reported by: Owned by:
Priority: low Milestone:
Component: dimensions Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:

jQuery 1-4-4

Internet Explorer 8 vs. Firefox 3.6.6

Win 7 x64

When I have my <body> element set to overflow:scroll, IE 8 gives the same width as without a scrollbar, while Firefox returns different values for the width with and without the scrollbar.

    $('div').append('<p>' + $(document).width() + '</p>');
    $('div').append('<p>' + $(document).width() + '</p>');
    $('div').append('<p>' + $(document).width() + '</p>');


Will return in firefox:




Will return in IE 8:




JSFiddle can be found here: JSFiddle

Attachments (0)
Change History (6)

Changed January 26, 2011 03:57PM UTC by jitter comment:1

component: unfileddimensions
priority: undecidedlow
resolution: → patchwelcome
status: newclosed

Thanks for taking the time to contribute to the jQuery project by writing a bug report.

I'm not convinced that this is a bug.

From my investigations it seems that IE in this case returns a different value then most other browsers for offsetWidth. But afaik offsetWidth isn't standardized by a W3C spec but comes from the MSIE DHTML object model.

I also don't understand why you are checking $(document).width() when setting styles on the body. If you do $("body").width() you should get the expected results. You could also resort to manually checking the scrollWidth which also should give you the value you want.

In any case I guess this isn't trivial to fix (if it is a bug at all), thus I close this ticket.

If you can provide a detailed rundown on why this indeed is a bug and you have a small patch (as pull request) available please report back.

Related reading:\\\\\\\\

Changed January 27, 2011 11:18AM UTC by comment:2

Ok accepted, I did do some other tests as well. But the bodyWidth is indeed the best solution. I still find it strange that the document doesn't give a right value when overflow: scoll is on, because it is only in IE8 and not in IE7.

IE8 pretends if the scrollbar isn't there, but does adjust its body to it.

Thanks for the advice.

Changed February 23, 2011 12:40AM UTC by jitter comment:3

#8345 is a duplicate of this ticket.

Changed January 26, 2012 11:46PM UTC by anonymous comment:4

Please review this as this is still an issue...

Changed January 26, 2012 11:48PM UTC by anonymous comment:5

Please reopen this as this is very much still an issue... Look below for details.

Changed October 14, 2012 01:14PM UTC by mikesherov comment:6

#12653 is a duplicate of this ticket.