JavaScript Window frameElement property

The frameElement property in JavaScript is a property of the Window object that refers to the frame or iframe element in which the current window is embedded. This property is null if the current window is not embedded in a frame or iframe element.

Here is an example of how the frameElement property works:

const frame = document.createElement('iframe');
frame.src = 'https://google.com';

document.body.appendChild(frame);

console.log(window.frameElement);  // logs the 'iframe' element

In the code example above, we use the document.createElement() method to create a new iframe element. We then set the src property of the iframe element to the Google homepage, and append the iframe element to the body element of the document.

Next, we use the console.log() method to log the value of the window.frameElement property to the console. Since the current window is embedded in the iframe element, the frameElement property will refer to the iframe element.

The frameElement property is typically used to access the frame or iframe element in which the current window is embedded. This can be useful in cases where you want to modify the properties or attributes of the frame or iframe element, such as its src property or width and height attributes.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: