Bug Tracker

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#15225 closed bug (notabug)

isWindow doesn't recognize wrapped window elements

Reported by: AKwaschny Owned by:
Priority: low Milestone: None
Component: core Version: 1.11.1
Keywords: isWindow Cc:
Blocked by: Blocking:

Description

Calling jQuery.isWindow() on a wrapped window element, e.g. jQuery(window), returns false.

Demo: http://jsfiddle.net/zp318pk7/

Change History (5)

comment:1 Changed 5 years ago by markelog

Component: selectorcore
Resolution: notabug
Status: newclosed

That's right it's not a Window object it's a jQuery object, it should return false.

comment:2 Changed 5 years ago by AKwaschny

So why does jQuery(window).is(window) return false as well? You are basically saying once the window is wrapped, it becomes something new. That's just wrong.

comment:3 Changed 5 years ago by gibson042

jQuery(window).is(window) returns false because window falls through the function, node, and string checks in the code enabling .is: https://github.com/jquery/jquery/blob/10399ddcf8a239acc27bdec9231b996b178224d3/src/traversing/findFilter.js#L11-L38. This would also be true of other non-DOM objects (e.g., jQuery([ Math ]).is( Math ) === false).

jQuery collections containing non-node members (or even non-element members, in many cases) don't always behave well, and .is is an area where we care about performance. But I wouldn't object to a small fix, if someone is interested in doing the legwork.

comment:4 Changed 5 years ago by dmethvin

jQuery.isWindow seems pretty well documented to examine its object and I don't know why it would strip off wrappers or try to look into the contents of the object it's given to find a window. http://api.jquery.com/jQuery.isWindow/

For jQuery(window).is(window) the docs say window isn't a valid input, so at most that would be a feature request. It's easy to do jQuery.isWindow(jQuery(window)[0]) http://api.jquery.com/is/

comment:5 Changed 5 years ago by AKwaschny

jQuery(document).is(document) returns true on the other hand. Well, I obviously don't get the philosophy of it. Anyway, thanks for the explanations everyone, I will just "adjust" this for my own then.

Note: See TracTickets for help on using tickets.