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).
Example
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 srcdoc attribute:
iframeObject.srcdoc
Set srcdoc attribute:
iframeObject.srcdoc = HTML_code
Attribute value
Value | Description |
---|---|
HTML_code | Specify the HTML content to be displayed in the iframe. It must be valid HTML syntax. |
Technical details
Return value: | String value, representing the HTML content displayed in the iframe (if any). |
---|
浏览器支持
表中的数字注明了首个完全支持该属性的浏览器版本。
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
20.0 | 不支持 | 25.0 | 6.0 | 15.0 |
相关页面
HTML 参考手册:HTML <iframe> srcdoc 属性