Window frameElement Property - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window frameElement

Description

The frameElement property returns the <iframe> element in which the current window is inserted.

If the document window is not placed within an <iframe>, the return value of this property is null.

This property is read-only.

Return Value

An IFrame object, which is the host of the current window, otherwise null

The following code shows how to check if the current window is in an <iframe>. If so, change its URL to "java2s.com":

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {/*from  w  ww .j  av  a2s. co  m*/
    var frame = window.frameElement;

    if (frame) {
        frame.src = "https://www.java2s.com/";
    }
}
</script>

</body>
</html>

Related Tutorials