HTML | DOM IFrame srcdoc Property
The HTML DOM IFrame srcdoc property is used to set or return the value of a srcdoc attribute of an <Iframe> element. The srcdoc attribute is used to specify the HTML content of the document in the <Iframe> element. It can be used together with the sandbox and seamless attributes.
Syntax:
- It returns the srcdoc property.
iframeObject.srcdoc
- It is used to set the srcdoc property.
iframeObject.srcdoc = HTML_code
- HTML_code: It is used to specify the HTML content of the page which will display in an Iframe element.
- Before Clicking on Button:

- After Clicking on Button:

- Before Clicking on Button:

- After Clcking on Button:

- Google Chrome 20.0
- Firefox 25.0
- Safari 6.0
- Opera 15.0
- HTML | <iframe> srcdoc Attribute
- HTML | DOM IFrame src Property
- HTML | DOM IFrame name Property
- HTML | DOM IFrame contentWindow Property
- HTML | DOM IFrame contentDocument Property
- HTML | DOM IFrame sandbox Property
- HTML | DOM IFrame width Property
- HTML | DOM IFrame height Property
- HTML | srcdoc Attribute
- HTML | <iframe> name Attribute
- HTML | <iframe> src Attribute
- HTML | DOM IFrame Object
- HTML | <iframe> longdesc Attribute
- HTML | <iframe> width Attribute
- HTML | <iframe> height Attribute
Property Values:
Return Value: It returns a string value which specify the HTML content of the page that are display in the Iframe element.
Example 1: This example illustrates how to return the Iframe srcdoc property.
<!DOCTYPE html> <html> <head> <title> HTML DOM iframe srcdoc Property </title> </head> <body style="text-align:center;"> <h1>GeeksforGeeks</h1> <h2>HTML DOM iframe srcdoc Property</h2> srcdoc="<p>GeeksForGeeks</p>" id="GFG" height="200" width="400" name="myGeeks"> </iframe> <br><br> <button onclick="Geeks()">Submit</button> <p id="sudo" style="font-size:20px"></p> <script> function Geeks() { var x = document.getElementById("GFG").srcdoc; document.getElementById("sudo").innerHTML = x; } </script> </body> </html> |
Output:
Example 2: This example illustrates how to set the Iframe srcdoc property.
<!DOCTYPE html> <html> <head> <title> HTML DOM iframe srcdoc Property </title> </head> <body style="text-align:center;"> <h1>GeeksforGeeks</h1> <h2>HTML DOM iframe srcdoc Property</h2> srcdoc="<p>GeeksForGeeks</p>" id="GFG" height="200" width="400" name="myGeeks"> </iframe> <br><br> <button onclick="Geeks()">Submit</button> <p id="sudo" style="font-size:20px"></p> <script> function Geeks() { var x = document.getElementById("GFG").srcdoc = "Hello Geeks"; document.getElementById("sudo").innerHTML = "The value of the srcdoc attribute " + "was changed to " + x; } </script> </body> </html> |
Output:
Supported Browsers: The browsers supported by HTML DOM IFrame srcdoc Property are listed below:
Recommended Posts:
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



