- HTML Tutorial
- HTML - Home
- HTML - History and Evolution
- HTML - Overview
- HTML - Editors
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Headings
- HTML - Paragraphs
- HTML - Quotations
- HTML - Comments
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Style Sheet
- HTML - CSS Classes
- HTML - CSS IDs
- HTML - Images
- HTML - Image Map
- HTML Tables
- HTML - Tables
- HTML - Headers & Caption
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Iframes
- HTML - Blocks
- HTML Backgrounds
- HTML - Backgrounds
- HTML Colors
- HTML - Colors
- HTML - RGB
- HTML - HEX
- HTML - HSL
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Code Builder
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - srcdoc Attribute
The srcdoc is an HTML attribute that specifies the HTML content on the page to show in the inline frame. If the srcdoc attribute is present in the <iframe> element, then it will override the content specified in the src attribute.
If the srcdoc attribute is not present in the <iframe> element, then it will show the file specified in the src attribute.
it can be used together with sandbox and seamless attribute.
Syntax
Following is the syntax of the srcdoc attribute −
<iframe srcdoc="HTML_code" >
HTML_code − It is used to specify the HTML content of the page which will display in an iframe element.
Example
In the following example, we are illustrating how to return the iframe srcdoc property in the HTML document.
<!DOCTYPE html> <html> <head> <title>HTML iframe srcdoc Attribute</title> </head> <body> <h1 style="color: green;">tutorials <span style="color: black">point</span> </h1> <h2>HTML iframe srcdoc Attribute</h2> <iframe src="https://tutorialspoint.com/index.htm" srcdoc=" <p>Hi, I am tutorialspoint</p>" id="content" height="100" width="300" name="myGeeks"> </iframe> <br> <button onclick="submit()"> Submit </button> <p id="demo" style="font-size:20px"></p> <script> function submit() { let x = document.getElementById("content").srcdoc; document.getElementById("demo").innerHTML = x; } </script> </body> </html>
On executing the above script, it will generate an output consisting of the iframe text along with a click button. when the user clicks the button it will displays the text entered in the iframe.
Example
The following example shows how to set or override the iframe srcdoc attribute based on the previously specified content of the srcdoc attribute.
<!DOCTYPE html> <html> <head> <title>HTML iframe srcdoc Attribute</title> </head> <body> <h1 style="color: green;">tutorials <span style="color: black">point</span> </h1> <h2>HTML iframe srcdoc Attribute</h2> <iframe src="https://tutorialspoint.com/index.htm" srcdoc=" <p>Hi, I am tutorialspoint</p>" id="content" height="50" width="300" name="myGeeks"> </iframe> <br> <button onclick="submit()"> Submit </button> <p id="demo" style="font-size:20px"></p> <script> function submit() { let x = document.getElementById("content").srcdoc = "tutorialspoint Easy to learn!"; document.getElementById("demo").innerHTML = "The value of the srcdoc attribute " + "was changed to " + x; } </script> </body> </html>
When we execute the above script, it will generate an output consisting of the iframe text along with thw button. when the user clicks the button it will displays the text in the iframe.
To Continue Learning Please Login
Login with Google