首頁  >  文章  >  web前端  >  如何在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 內容( 元素)顯示在

以上是如何在HTML中指定要在