HTML 中的 標記指定內嵌框架。此內嵌框架用於在目前 HTML 文件中嵌入另一個文件。所有瀏覽器都支援此標籤,例如 Google Chrome、Microsoft Edge/Internet Explorer、Firefox、safari 和 Opera 等。
標籤的「srcdoc」屬性用於指定要在頁面中顯示的HTML內容
範例 1
在下面的範例中,我們使用帶有 標籤的「srcdoc」屬性來指定要在 HTML 中的 中顯示的頁面(
元素)的 HTML 內容。
<!DOCTYPE html>
<html>
<head>
<title>
How to specify the HTML content of the page to show in the "iframe" in HTML?
</title>
</head>
<body>
<h3 id="How-to-specify-the-HTML-content-of-the-page-to-show-in-the-iframe-in-HTML">How to specify the HTML content of the page to show in the "iframe" in HTML?</h3>
<p>We can do it by using <b>srcdoc</b> attribute of iframe in HTML.</p>
<iframe srcdoc="<h2 id="You-can-find-any-tutorial-on-tutorialspoint">You can find any tutorial on tutorialspoint</h2>">
<p>Browser does not support iframes.</p>
</iframe>
</body>
</html>
登入後複製
如我們在輸出中所看到的,文件中的 HTML 內容(
元素)顯示在 中。
範例 2
以下是 HTML Iframe 的另一個範例,在此,我們在 iframe 中建立了一個表格。
<!DOCTYPE html>
<html>
<head>
<title>
How to specify the HTML content of the page to show in the "iframe" in HTML?
</title>
</head>
<body>
<h3 id="How-to-specify-the-HTML-content-of-the-page-to-show-in-the-iframe-in-HTML">How to specify the HTML content of the page to show in the "iframe" in HTML?</h3>
<p>We can do it by using <b>srcdoc</b> attribute of iframe in HTML.</p>
<iframe srcdoc="<table border = 3>
<caption> Abbreviations </caption>
<tr>
<th> HTML </th>
<th> CSS </th>
</tr>
<tr>
<td> Hypertext markup language</td>
<td> Cascading style sheet </td>
</tr>
</table>">
<p>Browser does not support iframes.</p>
</iframe>
</body>
</html>
登入後複製
如我們在輸出中所看到的,文件中的 HTML 內容(HTML 表格)顯示在 中。
範例 3
預設情況下,所有瀏覽器都會將 顯示為預設值。我們可以使用CSS來改變的樣式。
在下面的範例中,
我們透過使用 CSS 來更改 的寬度、高度和邊框來更改其樣式。
我們使用帶有 標記的「srcdoc」屬性來指定要在 HTML 中的 中顯示的頁面( 元素)的 HTML 內容。
<!DOCTYPE html>
<html>
<head>
<title>
How to specify the HTML content of the page to show in the "iframe" in HTML?
</title>
</head>
<body>
<h3 id="How-to-specify-the-HTML-content-of-the-page-to-show-in-the-iframe-in-HTML">How to specify the HTML content of the page to show in the "iframe" in HTML?</h3>
<p>We can do it by using <b>srcdoc</b> attribute of iframe in HTML.</p>
<iframe srcdoc="<div> Hello Disha</div>" width="50%" height="100" style="border:3px solid green;">
<p>Browser does not support iframes.</p>
</iframe>
</body>
</html>
登入後複製
如我們在輸出中所看到的,文件中的 HTML 內容( 元素)顯示在 中,我們也使用 CSS 更改了 的樣式。