Window frameElement property

Definition and usage

frameElement The property returns the frame in which the window is running.

If the window is not running in a frame, then frameElement The property returns null.

frameElement The property is read-only.

Tip:A frame can be any embedded element:<frame>, <iframe>, <embed>, <object> et al.

See also:

length attribute

frames attribute

Instance

Example 1

Is the current window in a frame?

if (window.frameElement) {
  let answer = "YES";
}

Try it yourself

Example 2

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

const frame = window.frameElement;
if (frame) {
  frame.src = "https://www.codew3c.com/";
}

Try it yourself

Syntax

window.frameElement

Or:

frameElement

Return value

Type Description
Object.

The host of the window (parent document).

If 'host' does not exist, it is null.

Browser support

All browsers support window.frameElement

Chrome IE Edge Firefox Safari Opera
Chrome IE Edge Firefox Safari Opera
Support Support Support Support Support Support

Related Pages

HTML DOM IFrame Object

HTML <iframe> Tag