jQuery isWindow() Method

Beginner
6 min read
Updated: Oct 2026
4 examples
Live preview

What Is isWindow()?

jQuery.isWindow(obj) (alias $.isWindow) returns true when obj is a browser window — the current page window or an iframe’s contentWindow (added in jQuery 1.4.3).

Remember
$.isWindow(obj)  → true | false

$.isWindow(window)  // true
$.isWindow({})      // false
$.isWindow(document.body)  // false

// Official replacement (jQuery 3.3+):
function isWindow(obj) {
  return obj != null && obj === obj.window;
}
NeedUse
Legacy jQuery check$.isWindow(obj)
Modern replacementobj != null && obj === obj.window
Plain object map?$.isPlainObject(obj)

How to Use isWindow()

Pass a candidate object; branch when it is a browsing context window.

  1. Start with a value that might be a window (context arg, iframe handle, etc.).
  2. Call $.isWindow(obj) — or the official one-liner replacement.
  3. If true, treat it as a window (read document, size, location, …).
  4. If false, handle as a normal object or DOM node instead.
PieceRequired?Role
objYesValue to test
Return—Boolean — is it a window?
Core idea—obj === obj.window identity check

Pseudocode

Pseudocode
function isWindow(obj):
    // official jQuery recommendation
    return obj != null and obj === obj.window

// Typical use:
if isWindow(context):
    doc = context.document
else:
    // treat as element / plain object / other

Cheat Sheet

Keep these facts handy while detecting window objects with jQuery.

TopicDetail
SyntaxjQuery.isWindow(obj) / $.isWindow(obj)
SincejQuery 1.4.3
StatusDeprecated 3.3 · removed 4.0
Truewindow, same-origin iframe.contentWindow
False{}, DOM nodes, document, null
Replace withobj != null && obj === obj.window
Related$.isPlainObject(), Window

Live Preview

Pick a sample value and see what $.isWindow() returns.

Browser demo of $.isWindow() — same idea as the examples below.

Result
$.isWindow(window)
→ true

/* current browsing context */

jQuery Examples

Short, copy-ready snippets. Open DevTools Console, or use Try It Yourself for a live editor.

Example 1 — Detect the Global window

The current page browsing context passes the test.

jQuery
console.log($.isWindow(window));              // true
console.log(window === window.window);        // true
console.log($.isWindow(self));                // true (same window)
Try It Yourself

How It Works

  1. Global window. $.isWindow(window) is true for the page context.
  2. Self reference. A window’s .window property points back to itself.
  3. Alias. self refers to the same window in normal pages → also true.
  4. Use. Branch when a function received a window as its context.

Example 2 — Values That Are Not Windows

Plain objects, the document, and DOM nodes all fail.

jQuery
console.log($.isWindow({}));              // false
console.log($.isWindow(document));        // false
console.log($.isWindow(document.body));   // false
console.log($.isWindow(null));            // false
Try It Yourself

How It Works

  1. Plain object. {} has no .window self-link → false.
  2. Document. The document is not a window (it lives inside one).
  3. Element. DOM nodes are host objects, not browsing contexts.
  4. Null. null is rejected up front (obj != null).

Example 3 — Official Replacement Helper

Copy the one-liner from the jQuery API for jQuery 4+ or vanilla code.

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

console.log(isWindow(window));  // true
console.log(isWindow({}));      // false
console.log($.isWindow(window) === isWindow(window));  // true
Try It Yourself

How It Works

  1. Null guard. obj != null skips null and undefined.
  2. Identity. obj === obj.window is true only for Window objects.
  3. Parity. Matches $.isWindow on jQuery 3.x for normal cases.
  4. Migrate. Keep this helper when you drop $.isWindow.

Example 4 — Same-Origin iframe.contentWindow

An iframe’s window is also a Window — when you can access it.

jQuery
// <iframe id="frame" src="about:blank"></iframe>
var frame = document.getElementById("frame");
var win = frame.contentWindow;

console.log($.isWindow(win));   // true
console.log($.isWindow(frame)); // false (element, not window)
Try It Yourself

How It Works

  1. Element vs window. The <iframe> node is not a window.
  2. contentWindow. That property holds the iframe’s browsing context.
  3. Check. $.isWindow(win) returns true for same-origin frames.
  4. Cross-origin. Access may throw — wrap reads in try/catch in real apps.

Edge Cases & Pitfalls

Check these before relying on $.isWindow() in plugins.

deprecated

Gone in jQuery 4.0

Copy the official helper: obj != null && obj === obj.window. Do not depend on $.isWindow in new code.

typeof

typeof window === "object" is not enough

Arrays, null (historically), and DOM nodes also look like objects. Use the identity check instead.

iframe

Cross-origin iframes throw

Reading contentWindow or its properties across origins can throw. Catch errors before calling isWindow.

document

Document ≠ window

document lives inside a window. $.isWindow(document) is false — use document.defaultView when you need the window from a document.

Browser Support

jQuery.isWindow() needs jQuery 1.4.3–3.x in the browser. It was deprecated in 3.3 and removed in jQuery 4.0. The official one-liner works in all modern browsers without jQuery.

✓ Deprecated · jQuery 3.3

jQuery.isWindow()

Available with jQuery 1.4.3–3.x in Chrome, Firefox, Safari, and Edge. Prefer obj != null && obj === obj.window for new code. Not present in jQuery 4.0.

Legacy jQuery 3.x only
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
$.isWindow() jQuery 1.4.3–3.x

Bottom line: Use $.isWindow(obj) only in jQuery 3.x legacy apps. For new projects, use obj != null && obj === obj.window.

Performance Notes

ApproachCostBest for
$.isWindow(obj)O(1)Legacy jQuery context checks
obj === obj.windowO(1)Modern / vanilla replacement
typeof obj === "object"O(1)Too broad — avoid for windows

The check is a couple of property reads. Cost is never the issue — correctness (and same-origin iframe access) is.

Key Takeaways

  • Role: $.isWindow(obj) → is this a browser window?
  • Core test: obj != null && obj === obj.window.
  • Status: deprecated in 3.3, removed in 4.0.
  • Also true: same-origin iframe.contentWindow.

One line: a window is the object that equals its own .window — learn $.isWindow for legacy code, ship the official one-liner in new code.

Frequently Asked Questions

jQuery.isWindow(obj) returns true when obj is a browser window object — the global window or an iframe's contentWindow. It returns false for plain objects, DOM elements, document, null, and primitives.
Yes. It was deprecated in jQuery 3.3 and removed in jQuery 4.0. jQuery recommends reimplementing it as: function isWindow(obj) { return obj != null && obj === obj.window; }
jQuery uses window detection internally when deciding whether a context is the global browsing context or an iframe — for example when resolving document roots and comparing execution contexts.
isPlainObject returns true for simple {} maps. isWindow returns true only for window objects. $.isPlainObject(window) is false, and $.isWindow({}) is false.
No. typeof window is "object", but so are arrays and DOM nodes. isWindow uses the obj === obj.window identity check that specifically identifies window objects.
Yes, when you can access the iframe's contentWindow (same-origin). Cross-origin iframes block access and throw a security error — catch that before testing.

Next: isXMLDoc()

Learn how jQuery detects XML document nodes versus HTML.

isXMLDoc tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful