Skip to main content

Bug Tracker

Side navigation

#12310 closed bug (wontfix)

Opened August 15, 2012 04:18PM UTC

Closed August 15, 2012 11:08PM UTC

Last modified April 19, 2013 10:32AM UTC

$(window).height() and .width() do not work in IE6 and IE7

Reported by: ebradsha Owned by: ebradsha
Priority: low Milestone: 1.next
Component: dimensions Version: 1.8.0
Keywords: Cc:
Blocked by: Blocking:
Description

I originally opened a ticket for this issue under #12300. However, it was prematurely closed out as 'worksforme' and I do not have the ability to re-open the bug.

Using $(window).width() and $(window).height() previously worked correctly with jQuery <1.8.0. In version 1.8.0, a value of 0 is always returned.

I have produced this bug under IE6 and IE7, I have not tested on other versions of IE.

I have tested this on multiple machines running IE6 and IE7 at multiple client sites with the same result every time. Unlike dmethvin, I do not have access to BrowserStack so I cannot speculate why the code worked on BrowserStack for him.

Here is a screenshot demonstrating the bug:

http://s16.postimage.org/6zvnkd6r9/jquery_window_width_bug.png

Please let me know if you require any further demonstration of this bug to pursue debugging. I would be more than happy to grant a jQuery team member access to a VM running IE6 or IE7 so they can see this bug in action for themselves.

Attachments (0)
Change History (18)

Changed August 15, 2012 04:23PM UTC by dmethvin comment:1

You weren't giving us complete information. Your test cases don't match what you have in the screen shot.

script defer is unfixably unreliable in IE. There's not even a reason to use it the way you do in the test case.

https://github.com/h5bp/lazyweb-requests/issues/42

Can I close this **now**, or do you want to propose a solution of some kind after thoroughly reading the link above?

Changed August 15, 2012 04:24PM UTC by dmethvin comment:2

owner: → ebradsha
status: newpending

Changed August 15, 2012 04:25PM UTC by ebradsha comment:3

status: pendingnew

You can take out the defer, the bug remains. I put in the defer so the body text would load before the alert came up. Would you like me to post a new screenshot?

Changed August 15, 2012 04:28PM UTC by dmethvin comment:4

status: newpending

Please come up with a test case and stick to it.

Changed August 15, 2012 04:30PM UTC by ebradsha comment:5

status: pendingnew

Here is the new screenshot:

http://s9.postimage.org/fuwrmbmgf/jquery_window_width_bug_no_defer.png

I'd be more than happy to grant you access to a dev VM running this test. Do you have a support/bugs email address I could send the login info to?

Changed August 15, 2012 04:37PM UTC by dmethvin comment:6

status: newpending

We have to be able to repro it, otherwise we can't create a unit test against it. To simplify recreating the problem and to be sure we're looking at the same code, can you post that page somewhere?

Changed August 15, 2012 04:46PM UTC by ebradsha comment:7

status: pendingnew

Here's an uploaded version, I added .height() in there as well:

http://199.127.56.68/jquerybug12310.html

Changed August 15, 2012 04:49PM UTC by ebradsha comment:8

Screenshot of my results from the online version:

http://s15.postimage.org/hg24bmrzv/jquery_bug_online_example.png

Changed August 15, 2012 04:59PM UTC by nnyby comment:9

I'm seeing this behavior in IE9 as well. Calling $(window).width() or $(window).height() with jQuery 1.8 returns 0. Using "document" instead of "window" works as expected, though.

Changed August 15, 2012 05:31PM UTC by timmywil comment:10

component: unfileddimensions
milestone: None1.next
priority: undecidedlow
status: newopen

Changed August 15, 2012 06:11PM UTC by anonymous comment:11

This appears to have been broken by Pull Request https://github.com/jquery/jquery/pull/764 when a change was made to the dimensions.js file

There used to be a fallback check for the clientWidth off of the body, but that was taken out

Before Pull Request:

	
if ( jQuery.isWindow( elem ) ) {
    // 3rd condition allows Nokia support, as it supports the docElem prop but not CSS1Compat
    doc = elem.document;
    docElemProp = doc.documentElement[ clientProp ];
    return jQuery.support.boxModel && docElemProp ||
        doc.body && doc.body[ clientProp ] || docElemProp;
}

After Pull Request:

if ( jQuery.isWindow( elem ) ) {
    // As of 5/8/2012 this will yield incorrect results for Mobile Safari, but there
    // isn't a whole lot we can do. See pull request at this URL for discussion:
    // https://github.com/jquery/jquery/pull/764
    return elem.document.documentElement[ clientProp ];
}

If we add back in the fallback for the body check it fixes IE9. I've tested locally using the above JSBin that Timmy made with a tunnel to my localmachine with the updated code.

Proposed Slightly Reverted Code:

	
if ( jQuery.isWindow( elem ) ) {
    doc = elem.document;
    return doc.documentElement[ "client" + name ] || 
        doc.body && doc.body[ "client" + name ];
}

The trick is to know if this fix still addresses whatever was the intention of the Pull Request made 3 months ago. Seeing that how difficult this was to recreate the issue, I'm not sure how easy it will be to create a unit test showing that this fails inside our normal qunit test module.

I'll try to see if I can recreate the issue in a unit test within our existing qunit test suite and see if the above proposed fix addresses the original issue that was being addressed in the previous Pull Request.

Changed August 15, 2012 06:14PM UTC by elijahmanor comment:12

^ That was me by the way... didn't realize I wasn't logged into the system ;)

Changed August 15, 2012 07:57PM UTC by mikesherov comment:13

resolution: → wontfix
status: openclosed

Changed August 15, 2012 07:58PM UTC by mikesherov comment:14

keywords: → needsdocs

We need to redocument our lack of quirks mode support.

Changed August 15, 2012 10:55PM UTC by mikesherov comment:15

keywords: needsdocs
resolution: wontfix
status: closedreopened

sorry, I missed the part where this wasn't quirks mode.

Changed August 15, 2012 11:08PM UTC by mikesherov comment:16

resolution: → wontfix
status: reopenedclosed

Actually, it is quirks mode!

http://stackoverflow.com/questions/69828/must-doctype-be-the-very-first-tag-in-an-html-document

http://jsbin.com/otipoq/11/

Apparently, jsbin renderes everything in Quirks Mode?!?

<script>setInterval=setTimeout;</script><!DOCTYPE html>

Changed August 15, 2012 11:36PM UTC by mikesherov comment:17

Remi just fixed JSBin, and the JSBin example no longer exhibits this issue.

https://github.com/remy/jsbin/issues/312#issuecomment-7772785

Won't fix it stays.

Changed April 19, 2013 10:32AM UTC by datta.may15@gmail.com comment:18

$(window).height() returns 0 in IE 10. for time being I am using $(document).height()