Javascript DOM HTML IFrame srcdoc Property set

Introduction

Change the HTML content that is shown in an iframe:

document.getElementById("myFrame").srcdoc = "<p>Some new content inside the iframe!</p>";

Click the button to change the HTML content that is shown in the iframe.

View in separate window

<!DOCTYPE html>
<html>
<body>

<iframe id="myFrame" srcdoc="<p>Hello world!</p>" src="https://www.java2s.com"></iframe>
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {//from   www . j  a  va 2s. c o  m
  document.getElementById("myFrame").srcdoc = "<p>Some new content inside the iframe!</p>";
}
</script>

</body>
</html>

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

The srcdoc attribute specifies the HTML content to show in the inline frame.

Property Values

Value Description
HTML_code Specifies the HTML content to show in the iframe.

The srcdoc property returns a String representing the HTML content that is shown in the iframe.




PreviousNext

Related