您好,欢迎访问一九零五行业门户网

如何在HTML中指定要在<iframe>中显示的页面的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内容?的详细内容。
其它类似信息

推荐信息