IFrame srcdoc attribute
Definition and usage
srcdoc
Attribute settings or returns the iframe element srcdoc attribute value.
The srcdoc attribute specifies the HTML content of the page to be displayed in the iframe.
Tip:This attribute should be used with sandbox and seamless attribute Used together.
If the browser supports the srcdoc attribute, it will override the content specified in the src attribute (if it exists).
If the browser does not support the srcdoc attribute, it will display the file specified in the src attribute (if it exists).
Instance
Example 1
Change the HTML content displayed in the iframe:
document.getElementById("myFrame").srcdoc = "<p>Some new content in the iframe!</p>";
Example 2
Return the HTML content displayed in the iframe:
var x = document.getElementById("myFrame").srcdoc;
Syntax
Return the srcdoc attribute:
iframeObject.srcdoc
Set the srcdoc attribute:
iframeObject.srcdoc = HTML_code
Attribute value
Value | Description |
---|---|
HTML_code | Specifies the HTML content to be displayed in the iframe. It must be valid HTML syntax. |
Technical details
Return value: | The string value indicates the HTML content displayed in the iframe (if any). |
---|
Browser Support
The numbers in the table indicate the first browser version that fully supports this attribute.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
20.0 | Not Supported | 25.0 | 6.0 | 15.0 |
Related Pages
HTML Reference Manual:HTML <iframe> srcdoc Attribute