HTML DOM Window frameElement Property


The HTML DOM Window frameElement property returns a HTML element corresponding to the window in which it is embedded such as <embed>, <iframe>, or <object>.

Syntax

Following is the syntax −

Returning window embedding element

window.frameElement

Example

Let us see an example of HTML DOM Window frameElement property −

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM Window frameElement</title>
<style>
   * {
      padding: 2px;
      margin:5px;
   }
   form {
      width:70%;
      margin: 0 auto;
      text-align: center;
   }
   input[type="button"] {
      border-radius: 10px;
</style>
</head>
<body>
   <form>
      <fieldset>
         <legend>HTML-DOM-Window-frameElement</legend>
         <input id="urlSelect" type="url" placeholder="Type URL here...">
         <input type="button" value="Go To" onclick="goToURL()">
         <div id="divDisplay"></div>
      </fieldset>
   </form>
   <script>
   var urlSelect = document.getElementById("urlSelect");
   var divDisplay = document.getElementById("divDisplay");
   function goToURL() {
      if(window.frameElement){
         window.frameElement.src=urlSelect.value;
         divDisplay.textContent = 'Current Window is embedded';
      }
      else
         divDisplay.textContent = 'Current Window is not embedded';
      }
   </script>
</body>
</html>

Output

Clicking ‘Go To’ button with url field set −

Changed source of embedding element −

Updated on: 21-Dec-2021

167 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements