JavaScript Window top Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Property

Definition

window.top is the outermost window. On a top-level page, top === window.

Syntax

Read window.top with no parentheses.

JavaScript
window.top;
CallWhat it does
window.topThe topmost window in the frame tree.

Window property in browsers. No import required.

Parameters

ParameterDescription
window.topRead-only or assignable depending on the property. No function arguments.

Return Value

Return ValueDescription
*The topmost window in the frame tree.

JavaScript Examples

Example 1 — Basic Read

Beginner example for window.top.

JavaScript
console.log(window.top === window);
console.log(window.top === window.parent);
Try It Yourself

How It Works

  1. Step. Top-level: top, parent, and window match.
  2. Step. Deep frames can differ.

Example 2 — Practical Use

Beginner example for window.top.

JavaScript
console.log(window.top.location.href.length > 0);
Try It Yourself

How It Works

  1. Step. Same-origin top exposes location.
  2. Step. Cross-origin top may throw if you dig deeper.

Example 3 — Check / Compare

Beginner example for window.top.

JavaScript
const framed = window.top !== window;
console.log(framed);
Try It Yourself

How It Works

  1. Step. A simple frame check.
  2. Step. false means this page is not nested.

Browser & Runtime Support

window.top is a standard Window property in browsers.

✓ Browser Window API

window.top

Available in all modern browsers. Not used in plain Node.js without a DOM.

Browsers Environment
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
window.top Excellent

Bottom line: Safe in browsers. Skip in server-only Node scripts.

Frequently Asked Questions

The topmost window of the frame hierarchy.
When your script runs inside one or more iframes.
parent is immediate parent; top walks all the way up.
Open the Window Properties index for every property in this series.

Browse more properties

Continue through the Window properties list.

Next →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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