Window frameElement

Example

Is the current window in a frame?

if (window.frameElement) {
  let answer = "YES";
}
Try it Yourself »

More example below.


Description

The frameElement property returns the frame where the window runs.

The frameElement property returns null if the window does not run in a frame.

The frameElement property is read only.

Note

A frame can be any embedding element:

<frame>, <iframe>, <embed>, <object>, etc.

See Also:

The length Property

The frames Property


Syntax

window.frameElement
or:
frameElement

Return Value

Type Description
An objectThe host of the window (the parent document).
Or null if no host exists.


More Examples

Example

If the window is in a frame, change the URL to "w3schools.com":

const frame = window.frameElement;

if (frame) {
  frame.src = "https://www.w3schools.com/";
}
Try it Yourself »


Browser Support

window.frameElement is supported in all browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes Yes


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.