IFrame srcdoc Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:IFrame


The srcdoc property sets or gets the srcdoc attribute in an iframe element, which controls the HTML content in the iframe.

Set the srcdoc property with the following Values

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

Return Value

A String, representing the HTML content that is shown in the iframe (if any)

The following code shows how to change the HTML content in an iframe:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<iframe id="myFrame" srcdoc="<p>Hello world!</p>" src="http://java2s.com"></iframe>

<button onclick="myFunction()">Test</button>

function myFunction() {/*from w  ww .jav a 2  s. c o m*/
    document.getElementById("myFrame").srcdoc = "<p>Some new content inside the iframe!</p>";


Related Tutorials