中顯示的頁(yè)面的HTML內(nèi)容?”>
在本文中,我們需要在iframe中顯示頁(yè)面的HTML內(nèi)容;瀏覽器窗口劃分為單獨(dú)的頁(yè)面。我們可以使用 標(biāo)記及其 srcdoc 屬性來(lái)完成此任務(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”屬性用于指定要在頁(yè)面中顯示的HTML內(nèi)容。該屬性將 HTML_code 作為值并指定要在 中顯示的頁(yè)面的 HTML 內(nèi)容。
示例 1
在下面的示例中,我們使用帶有 標(biāo)記的“srcdoc”屬性來(lái)指定要在 HTML 中的 中顯示的頁(yè)面(
元素)的 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ù)制
正如我們?cè)谳敵鲋锌吹降模臋n中的 HTML 內(nèi)容(
元素)顯示在 中。
示例 2
以下是 HTML Iframe 的另一個(gè)示例,在此,我們?cè)?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ù)制
正如我們?cè)谳敵鲋锌吹降?,文檔中的 HTML 內(nèi)容(HTML 表格)顯示在 中。
示例 3
默認(rèn)情況下,所有瀏覽器都會(huì)將 顯示為默認(rèn)值。我們可以使用CSS來(lái)改變的樣式。
在下面的示例中,
我們通過(guò)使用 CSS 更改 的寬度、高度和邊框來(lái)更改其樣式。
我們使用帶有 標(biāo)記的“srcdoc”屬性來(lái)指定要在 HTML 中的 中顯示的頁(yè)面( 元素)的 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ù)制
正如我們?cè)谳敵鲋锌吹降?,文檔中的 HTML 內(nèi)容( 元素)顯示在 中,并且我們還使用 CSS 更改了 的樣式。
以上就是如何在HTML中指定要在<iframe>中顯示的頁(yè)面的HTML內(nèi)容?的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注www.92cms.cn其它相關(guān)文章!






