HTML - srcdoc 屬性



HTML **srcdoc** 屬性指定要在內聯框架中顯示的頁面上的 HTML 內容。

如果 **<iframe>** 元素中存在 srcdoc 屬性,則它將覆蓋 src 屬性中指定的內容。如果 **<iframe>** 元素中不存在 srcdoc 屬性,則它將顯示 src 屬性中指定的文件。

它可以與 sandbox 和 seamless 屬性一起使用。

語法

<tag srcdoc="HTML_code" >

**HTML 程式碼:** 用於指定將在 iframe 元素中顯示的頁面 HTML 內容。

應用於

以下列出的元素允許使用 HTML **srcdoc** 屬性。

元素 描述
<iframe> HTML <iframe> 標籤用於建立內聯框架。

HTML srcdoc 屬性示例

下面的示例將說明 HTML srcdoc 屬性,以及我們應該在哪裡以及如何使用此屬性!

使用帶有 "iframe" 標籤的 srcdoc 屬性

srcdoc 屬性中提供的內容顯示在輸出視窗中。

<!DOCTYPE html>
<html>

<head>
      <title>HTML iframe srcdoc Attribute</title>
</head>

<body>
      <h1>HTML iframe srcdoc Attribute</h1>
      <iframe srcdoc="<p>Hi, I am tutorialspoint. I provide easy 
      learning tutorials. Have a happy learning experience.</p>" 
               height="100" 
               width="300">
      </iframe>
</body>

</html>

使用 srcdoc 覆蓋 src 屬性的內容

srcdoc 中的內容替換了 src 屬性中提供的 tutorialspoint 網站。

<!DOCTYPE html>
<html>
<body>
      <h3>HTML srcdoc Attribute</h3>
      <strong>Normal Iframe</strong>
      <br>
      <iframe src=
"https://tutorialspoint.tw/html/html_overview.htm"
              height=400 
              width="500">
      </iframe>
      <br>
      <strong>Normal Iframe</strong>
      <br>
      <iframe src=
"https://tutorialspoint.tw/html/html_overview.htm"
              srcdoc=
    "<p>We ere representing HTML Introduction Post</p>" 
              height=400 
              width="500">
      </iframe>
      
</body>

</html>

支援的瀏覽器

屬性 Chrome Edge Firefox Safari Opera
srcdoc 20.0 79.0 25.0 6.0 15.0
html_attributes_reference.htm
廣告
© . All rights reserved.