Example 1 — Basic Read
Beginner example for window.top.
console.log(window.top === window);
console.log(window.top === window.parent); How It Works
- Step. Top-level: top, parent, and window match.
- Step. Deep frames can differ.

window.top is the outermost window. On a top-level page, top === window.
Read window.top with no parentheses.
window.top; | Call | What it does |
|---|---|
window.top | The topmost window in the frame tree. |
Window property in browsers. No import required.
| Parameter | Description |
|---|---|
| window.top | Read-only or assignable depending on the property. No function arguments. |
| Return Value | Description |
|---|---|
| * | The topmost window in the frame tree. |
Beginner example for window.top.
console.log(window.top === window);
console.log(window.top === window.parent); Beginner example for window.top.
console.log(window.top.location.href.length > 0); Beginner example for window.top.
const framed = window.top !== window;
console.log(framed); window.top is a standard Window property in browsers.
Available in all modern browsers. Not used in plain Node.js without a DOM.
Bottom line: Safe in browsers. Skip in server-only Node scripts.
Continue through the Window properties list.
CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
9 people found this page helpful