W3Schools.com

Window top Property

Window Object Reference Window Object

Definition and Usage

The top property returns the topmost browser window of the current window.

Syntax

window.top


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The top property is supported in all major browsers.


Example

Example

When the "Check window" button is clicked, the function check() is called and the current window status is checked. If the topmost window (window.top) is different from the current window (window.self), then output that "This window is not the topmost window! Am I in a frame?". If the topmost window equals the current window, then fire the else statement:

<html>
<head>
<script type="text/javascript">
function check()
{
if (window.top!=window.self)
  {
  document.write("<p>This window is not the topmost window! Am I in a frame?</p>")
  }
else
  {
  document.write("<p>This window is the topmost window!</p>")
  }
}
</script>
</head>
<body>
<input type="button" onclick="check()" value="Check window" />
</body>
</html>

Try it yourself »


Window Object Reference Window Object
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
XML Editor - Free Trial!
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE