jQuery jQuery.isWindow() Method

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Window detect

What You’ll Learn

The jQuery.isWindow() utility returns true when a value is a browser window object — the global page context or an iframe’s contentWindow. This tutorial covers syntax, five worked examples, comparisons with $.type(), the jQuery 3.3 deprecation, and the official one-line replacement.

01

Syntax

$.isWindow(obj)

02

Boolean

true / false

03

window

Passes

04

{} no

Not window

05

iframe

contentWindow

06

3.3+

Deprecated

Introduction

In browser JavaScript, the global window object is special. It represents the browsing context — the tab or iframe that holds your page. Many values are technically “objects,” but only a true window has the window self-reference property that jQuery checks.

jQuery provides jQuery.isWindow() (also written $.isWindow()) to answer one question: “Is this value a browser window?” jQuery uses that answer internally when working with documents, iframes, and cross-context DOM operations. In jQuery 3.3 the method was deprecated; in jQuery 4.0 it was removed — but legacy plugins still rely on it, so understanding the pattern matters.

Understanding the jQuery.isWindow() Method

jQuery.isWindow(obj) returns true when obj is a window object — typically the page’s global window or an iframe’s contentWindow.

It returns false for null, primitives, plain objects, arrays, DOM elements, and document. The check is narrow by design: only window objects pass.

💡
Deprecation Notice

Since jQuery 3.3, use obj != null && obj === obj.window instead of $.isWindow(obj) in new code. This tutorial teaches both for maintenance and learning.

📝 Syntax

General form of jQuery.isWindow:

jQuery
jQuery.isWindow( obj )

// or

$.isWindow( obj )

Parameters

  • obj — any JavaScript value to test.

Return value

  • true if obj is a window object.
  • false for all other values.

Official replacement (jQuery 3.3+)

jQuery
function isWindow(obj) {

  return obj != null && obj === obj.window;

}



// Same result as $.isWindow(obj) in jQuery 3.x

console.log(isWindow(window)); // true

⚡ Quick Reference

Value$.isWindow()
windowtrue
iframe.contentWindowtrue
{}false
documentfalse
document.bodyfalse
nullfalse
"hello"false

📋 $.isWindow vs $.type vs $.isPlainObject

Three checks for three different object categories.

$.isWindow
window only

Browser context object

$.type
"object"

window is "object" too

$.isPlainObject
{} maps

window is not plain

Replacement
obj.window

jQuery 3.3+ pattern

Examples Gallery

Each example uses $.isWindow() (jQuery 3.7.1). Open DevTools or use the Try-it links to run them interactively.

📚 Getting Started

Core window detection — global context and common rejections.

Example 1 — Detect the Global window

The simplest case — the page’s browsing context passes the test.

jQuery
console.log($.isWindow(window)); // true



// window references itself — the key identity check

console.log(window === window.window); // true
Try It Yourself

How It Works

Every window object exposes a window property pointing to itself. jQuery’s check (and the official replacement) relies on that self-reference.

Example 2 — Plain Objects and DOM Nodes Are Not Windows

Values that look like objects but fail the window test.

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

typeof window === "object" is true, but so is typeof document. isWindow narrows the test to the one object type that equals its own .window property.

📈 Practical Patterns

Iframe contexts, guard functions, and the modern replacement.

Example 3 — Detect an iframe’s contentWindow

Each iframe has its own window object — also detected by isWindow.

jQuery
var frame = document.createElement("iframe");

document.body.appendChild(frame);



var childWin = frame.contentWindow;

console.log($.isWindow(childWin));       // true

console.log(childWin === childWin.window); // true
Try It Yourself

How It Works

jQuery uses window detection when resolving document roots across frames. An iframe’s contentWindow is a full window object with the same self-reference pattern as the top-level page.

Example 4 — Guard a Context Parameter

Accept either a window or a DOM element — branch safely.

jQuery
function getDocumentRoot(context) {

  if ($.isWindow(context)) {

    return context.document;

  }

  if (context && context.nodeType === 9) {

    return context; // already a document

  }

  if (context && context.ownerDocument) {

    return context.ownerDocument;

  }

  return document;

}



console.log(getDocumentRoot(window) === document);     // true

console.log(getDocumentRoot(document.body) === document); // true
Try It Yourself

How It Works

Plugin APIs sometimes accept “context” as either window or an element. isWindow is the first branch — before treating the value as a node.

Example 5 — Replace $.isWindow() in jQuery 3.3+

Official jQuery migration pattern — same logic, no deprecated API.

jQuery
function isWindow(obj) {

  return obj != null && obj === obj.window;

}



console.log(isWindow(window));        // true

console.log(isWindow({}));            // false

console.log(isWindow(null));          // false



// Matches $.isWindow() in jQuery 3.x

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

How It Works

jQuery documented this exact replacement when deprecating isWindow. Copy it into utility modules so plugins survive jQuery 4.0 without calling removed APIs.

🚀 Common Use Cases

  • Context resolution — distinguish window from element arguments.
  • iframe plugins — detect contentWindow before DOM queries.
  • Cross-frame utilities — verify you received a browsing context.
  • Legacy plugin maintenance — read existing $.isWindow checks.
  • Migration to jQuery 4 — swap in the obj === obj.window helper.
  • Reject mistaken inputs — block plain objects passed as “context.”

🧠 How jQuery.isWindow() Identifies a Window

1

Reject null

null and undefined return false immediately.

Filter
2

Read .window

Access obj.window — only window objects reference themselves.

Property
3

Strict equality

Compare obj === obj.window — the official replacement logic.

Compare
4

Return boolean

Plain objects, DOM nodes, and arrays fail — only window objects pass.

📝 Notes

  • Added in jQuery 1.4.3 — used internally across DOM and traversal code.
  • Deprecated in jQuery 3.3 — removed in jQuery 4.0.
  • Official replacement: obj != null && obj === obj.window.
  • $.type(window) returns "object" — not specific enough for window detection.
  • $.isPlainObject(window) returns false — window is never a plain map.
  • Works for iframe contentWindow objects the same as the top-level page.

Browser Support

jQuery.isWindow() has been available since jQuery 1.4.3. It works in all browsers where jQuery runs, but was deprecated in jQuery 3.3 and removed in jQuery 4.0.

jQuery 1.4.3+

jQuery jQuery.isWindow()

Present in jQuery 1.x–3.x. Deprecated in 3.3 — use obj === obj.window in new code. Not available in jQuery 4+.

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
jQuery.isWindow() Deprecated

Bottom line: Safe in jQuery 3.x maintenance code. For jQuery 4+ or new projects, inline the one-line isWindow replacement instead of calling $.isWindow().

Conclusion

The jQuery.isWindow() utility answers a narrow but important question: is this value a browser window? It powered jQuery’s cross-context DOM logic for years and remains readable in legacy plugins.

For new code on jQuery 3.3+, prefer the documented replacement obj != null && obj === obj.window. Understand isWindow when maintaining older code — and migrate before upgrading to jQuery 4 — then explore jQuery.isXMLDoc() for XML DOM detection.

💡 Best Practices

✅ Do

  • Use obj != null && obj === obj.window in jQuery 3.3+ projects
  • Check window before treating context as a DOM node
  • Test iframe contentWindow the same as top-level window
  • Migrate deprecated $.isWindow calls before jQuery 4
  • Pair with nodeType checks for full context resolution

❌ Don’t

  • Assume typeof x === "object" means window
  • Use $.isPlainObject to detect windows
  • Call $.isWindow() in new jQuery 4+ code — it was removed
  • Confuse document with window
  • Skip migration because the deprecated API still “works” in 3.x

Key Takeaways

Knowledge Unlocked

Five things to remember about jQuery.isWindow()

Detect browser windows the jQuery way.

5
Core concepts
02

window

Passes

Global
🚫 03

DOM

Fails

Reject
🔗 04

iframe

contentWindow

Frames
⚠️ 05

3.3+

obj.window

Migrate

❓ 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, null, and primitives.
Yes. jQuery.isWindow() 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. Both reject window for plain-object merging — 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 across browsers.
Avoid $.isWindow() in new projects. Use the one-line replacement obj != null && obj === obj.window, or test obj instanceof Window where supported. Keep $.isWindow() only when maintaining legacy jQuery plugins.
Did you know?

When jQuery deprecated isWindow, it published the entire implementation as a one-liner: obj != null && obj === obj.window. That pattern works because every browser window object has a window property that points back to itself — a quirk of the HTML spec that jQuery turned into a reliable type test.

Continue to jQuery.isXMLDoc()

Detect XML documents and XML DOM nodes vs HTML pages.

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.

6 people found this page helpful