Javascript DOM HTML IFrame name Property get

Introduction

Get the name of an iframe:

var x = document.getElementById("myFrame").name;

Click the button to display the name of the iframe.

View in separate window

<!DOCTYPE html>
<html>
<body>

<iframe id="myFrame" src="https://www.java2s.com" name="iframe_a"></iframe>
<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {// w  w w . j a  v a 2s .  c  o  m
  var x = document.getElementById("myFrame").name;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The name property sets or gets the value of the name attribute in an iframe element.

The name attribute sets the name of an iframe, and can be used to reference the element in a JavaScript.

We can use it as the value of the target attribute of an <a> or <form> element, or the form target attribute of an <input> or <button> element.

Value Description
name The name of the iframe

The name property returns String representing the name of the iframe.




PreviousNext

Related