Javascript DOM HTML IFrame width Property set

Introduction

Change the width of an iframe:

document.getElementById("myFrame").width = "400";

Click the button to change the width of the iframe to 400px.

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>

<script>
function myFunction() {/*w  ww .  jav a 2  s .co  m*/
  document.getElementById("myFrame").width = "400";
}
</script>

</body>
</html>

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

The width attribute specifies the width of an iframe.

Use the height property to set or return the value of the height attribute in an iframe.

The width property returns a String representing the width of the iframe, in pixels.




PreviousNext

Related