Javascript DOM HTML IFrame width Property get

Introduction

Return the width of an iframe:

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

Click the button to display the width of the iframe.

View in separate window

<!DOCTYPE html>
<html>
<body>

<iframe id="myFrame" src="https://www.java2s.com" height="200" width="250"></iframe>
<button onclick="myFunction()">Test</button>

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

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

</body>
</html>



PreviousNext

Related