目录

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
frameElement

Return Value

Type Description
An object The 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 "91xjr.com":

const frame = window.frameElement;

if (frame) {
  frame.src = "https://www.91xjr.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