2023如何在HTML中指定要在<iframe>中显示的页面的HTML内容?

 所属分类:web前端开发

 浏览:84次-  评论: 0次-  更新时间:2023-09-13
描述:更多教程资料进入php教程获得。 在本文中,我们需要在iframe中...
更多教程资料进入php教程获得。

如何在HTML中指定要在<iframe>中显示的页面的HTML内容?

在本文中,我们需要在iframe中显示页面的HTML内容;浏览器窗口划分为单独的页面。我们可以使用

HTML

HTML 中的 标记指定内联框架。该内联框架用于在当前 HTML 文档中嵌入另一个文档。所有浏览器都支持此标签,例如 Google Chrome、Microsoft Edge/Internet Explorer、Firefox、safari 和 Opera 等。

标签的“srcdoc”属性用于指定要在页面中显示的HTML内容

示例 1

在下面的示例中,我们使用带有

<!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 内容(

元素)显示在

示例 3

默认情况下,所有浏览器都会将

在下面的示例中,

  • 我们通过使用 CSS 更改

  • 我们使用带有

<!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 内容( 元素)显示在

积分说明:注册即送10金币,每日签到可获得更多金币,成为VIP会员可免金币下载! 充值积分充值会员更多说明»

讨论这个素材(0)回答他人问题或分享使用心得奖励金币

〒_〒 居然一个评论都没有……

表情  文明上网,理性发言!