中顯示的頁面的HTML內容?”>
在本文中,我們需要在iframe中顯示頁面的HTML內容;瀏覽器窗口劃分為單獨的頁面。我們可以使用 標記及其 srcdoc 屬性來完成此任務。
HTML 標簽
HTML 中的 標記指定內聯框架。該內聯框架用于在當前 HTML 文檔中嵌入另一個文檔。所有瀏覽器都支持此標簽,例如 Google Chrome、Microsoft Edge/Internet Explorer、Firefox、safari 和 Opera 等。
標簽的“srcdoc”屬性用于指定要在頁面中顯示的HTML內容。該屬性將 HTML_code 作為值并指定要在 中顯示的頁面的 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>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>
登錄后復制
正如我們在輸出中看到的,文檔中的 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>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>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 更改了 的樣式。
以上就是如何在HTML中指定要在<iframe>中顯示的頁面的HTML內容?的詳細內容,更多請關注www.92cms.cn其它相關文章!