Bug Tracker

Opened 10 years ago

Closed 10 years ago

#12901 closed bug (notabug)

isWindow returns true when it should be false

Reported by: [email protected] Owned by: [email protected]
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:


var x = {};
x.window = x;

$.isWindow(x); // returns true

why not use:

isWindow = function (obj) {
    return obj && obj !== null && obj === window;

instead of:

isWindow = function (obj) {
    return obj && obj !== null && obj === obj.window;

Change History (5)

comment:1 Changed 10 years ago by dmethvin

#12902 is a duplicate of this ticket.

comment:2 Changed 10 years ago by Rick Waldron

Those wouldn't match "window" from another frame.

comment:3 Changed 10 years ago by dmethvin

Owner: set to [email protected]
Status: newpending

Right, is *a* window. As for the bug, this is yet another case where we should not have exposed an internal utility method. But the test case seems pretty contrived anyway. Are you encountering this in real code as a result of calling $.isWindow() or is this manifesting in some other way?

comment:4 Changed 10 years ago by [email protected]

Status: pendingnew


This wasn't found via any real world occurrence, one of my devs noticed it while studying jQuery in a learning exercise.

I agree the example is contrived and unlikely in a real world scenario, I just couldn't see why obj == window wouldn't work.

Cheers Rob

comment:5 Changed 10 years ago by dmethvin

Resolution: notabug
Status: newclosed

Unfortunately, there's no simple test for seeing if something represents a window object that works from IE6 all the way to the latest browsers. We're good with what we have.

Note: See TracTickets for help on using tickets.