Javascript DOM HTML IFrame Objects get

Introduction

The IFrame object represents an HTML <iframe> element.

We can access an <iframe> element via document.getElementById():

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

Click the button to get the URL of the iframe.

View in separate window

<!DOCTYPE html>
<html>
<body>
<iframe id="myFrame" src="https://java2s.com"></iframe>
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {/*w  w  w .j  a va  2s . c  om*/
  var x = document.getElementById("myFrame").src;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related