Bug Tracker

Opened 14 years ago

Closed 14 years ago

#4136 closed bug (fixed)

Offset Bug in 1.3.1

Reported by: mike.helgeson Owned by: brandon
Priority: minor Milestone: 1.4
Component: offset Version: 1.3.1
Keywords: Cc:
Blocked by: Blocking:


Passing any non-element into the offset method throws an error... I think it should instead return zero values...

$( document ).offset(); ERROR $( window ).offset(); ERROR

Attachments (1)

offset_patch.js (2.6 KB) - added by mike.helgeson 14 years ago.

Download all attachments as: .zip

Change History (7)

Changed 14 years ago by mike.helgeson

Attachment: offset_patch.js added

comment:1 Changed 14 years ago by john

Component: dimensionsoffset
It looks like you added "
!this[0].ownerDocument" - doesn't seem too bad.

comment:2 Changed 14 years ago by thomasvsundert

I also experience this when trying to call position() (which invokes offset()) on an element within an IFrame. Please include the fix in the next version!

comment:3 Changed 14 years ago by thomasvsundert

Ok forget I said that, it's not true that the error occurs when it's called on elements within an IFrame. My error occured because I was trying to call $(undefined).position() and $(undefined) seems to return the HTML document, which then triggers the error.

comment:4 Changed 14 years ago by brandon

Resolution: invalid
Status: newclosed

You can't run offset on window and when you run offset with no matched elements it should return null as it does now in SVN Trunk. This matches the behavior of other methods that return a result based on the first matched element (like .width()).

comment:5 Changed 14 years ago by mike.helgeson

Resolution: invalid
Status: closedreopened

This function should return null. The issue is that is not happening in certain cases. Instead a javascript exception is thrown from:

$(window).offset() or $(document).offset()
TypeError: elem.ownerDocument is null

Maybe this is incorrect usage, but I feel like these calls should also return null, and not throw an error. Document and window are valid jquery object members, and don't cause errors in any other methods. Specifically, I have encountered this in my "drag" special event, I need to calculate the offset position... but I do not know if the event scope is going to be "document" or "window" and potentially break the code. I can test for document or window, but would rather have the "offset" and "position" methods test for "ownerDocument" The fix is quite simple...


if ( !elem ) return null;


if ( !elem || !elem.ownerDocument ) return null;

comment:6 Changed 14 years ago by brandon

Resolution: fixed
Status: reopenedclosed

fixed in r6319

Note: See TracTickets for help on using tickets.