中顯示的頁面的HTML內(nèi)容?”>
在本文中,我們需要在iframe中顯示頁面的HTML內(nèi)容;瀏覽器窗口劃分為單獨(dú)的頁面。我們可以使用 標(biāo)記及其 srcdoc 屬性來完成此任務(wù)。
HTML 標(biāo)簽
HTML 中的 標(biāo)記指定內(nèi)聯(lián)框架。該內(nèi)聯(lián)框架用于在當(dāng)前 HTML 文檔中嵌入另一個(gè)文檔。所有瀏覽器都支持此標(biāo)簽,例如 Google Chrome、Microsoft Edge/Internet Explorer、Firefox、safari 和 Opera 等。
標(biāo)簽的“srcdoc”屬性用于指定要在頁面中顯示的HTML內(nèi)容。該屬性將 HTML_code 作為值并指定要在 中顯示的頁面的 HTML 內(nèi)容。
示例 1
在下面的示例中,我們使用帶有 標(biāo)記的“srcdoc”屬性來指定要在 HTML 中的 中顯示的頁面(
元素)的 HTML 內(nèi)容。
<!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>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>You can find any tutorial on tutorialspoint</h2>"> <p>Browser does not support iframes.</p> </iframe> </body> </html>
登錄后復(fù)制
正如我們在輸出中看到的,文檔中的 HTML 內(nèi)容(
元素)顯示在 中。
示例 2
以下是 HTML Iframe 的另一個(gè)示例,在此,我們在 iframe 中創(chuàng)建了一個(gè)表格。
<!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>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>
登錄后復(fù)制
正如我們在輸出中看到的,文檔中的 HTML 內(nèi)容(HTML 表格)顯示在 中。
示例 3
默認(rèn)情況下,所有瀏覽器都會將 顯示為默認(rèn)值。我們可以使用CSS來改變的樣式。
在下面的示例中,
我們通過使用 CSS 更改 的寬度、高度和邊框來更改其樣式。
我們使用帶有 標(biāo)記的“srcdoc”屬性來指定要在 HTML 中的 中顯示的頁面( 元素)的 HTML 內(nèi)容。
<!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>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>
登錄后復(fù)制
正如我們在輸出中看到的,文檔中的 HTML 內(nèi)容( 元素)顯示在 中,并且我們還使用 CSS 更改了 的樣式。
以上就是如何在HTML中指定要在<iframe>中顯示的頁面的HTML內(nèi)容?的詳細(xì)內(nèi)容,更多請關(guān)注www.92cms.cn其它相關(guān)文章!