Bug Tracker

Opened 9 years ago

Closed 9 years ago

#7961 closed bug (patchwelcome)

$.fn.height or $.fn.width throw a TypeError Result of expression 'elem.document.body' [null] is not an object

Reported by: miowang@… Owned by: miowang@…
Priority: low Milestone: 1.next
Component: manipulation Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:

Description

in line 7151:

return elem.document.compatMode === "CSS1Compat" && elem.document.documentElement[ "client" + name ] ||
  elem.document.body[ "client" + name ];

if the elem.document.documentElement[ "client" + name ] is 0, this code will try to eval "elem.document.body[ "client" + name ] " and throw a type error

Change History (3)

comment:1 Changed 9 years ago by jitter

Component: unfiledmanipulation
Owner: set to miowang@…
Status: newpending

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

Please submit a reduced test case, which reproduces the issue you are experiencing, on http://jsfiddle.net. So that we can investigate this issue further.


How to report bugs

comment:2 in reply to:  1 Changed 9 years ago by miowang@…

Status: pendingnew

I know I should submit a test case, but as this exception only been thrown when window's width is 0, and in most condition, it can't show on http://jsfiddle.net/.

I found this issue is because my web app is visited by mobile device(like andorid), and sometimes the jquerymobile will try to invoke $(window).width() before the web view component is shown.

Replying to jitter:

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

Please submit a reduced test case, which reproduces the issue you are experiencing, on http://jsfiddle.net. So that we can investigate this issue further.


How to report bugs

comment:3 Changed 9 years ago by jitter

Priority: undecidedlow
Resolution: patchwelcome
Status: newclosed

So you are using jQuery mobile and not just jQuery core? Then maybe you should try and file this against the jQuery-Mobile bug tracker because they might have more knowledge about WebView specific bugs.

Also without more specific information or some test case which reproduces (at least sometimes) the error debugging this is difficult/impossible.

Is this error triggered by some of your code (e.g. by not using a ready wrapper or stuff like that) or by jQuery-Mobile on its own?

Overall this sounds pretty strange, normally you would call .width() only after the page has finished loading (e.g. inside the ready wrapper) and at this point clientWidth should work.

Are you sure the elem.document.documentElement[ "client" + name ] part of the conditional is failing or is already elem.document.compatMode === "CSS1Compat" evaluating to false.


With the currently available information this issue can't be fixed. If you happen to be able to create a test which reproduces this and this is indeed a bug in jQuery which can be workaround please report back and we will happily reopen this ticket.

Note: See TracTickets for help on using tickets.