如何在HTML5中新增外部(非HTML)應用程式的容器


在HTML5中新增外部應用程式容器,我們使用<embed>標籤。它定義或嵌入外部資源的容器,例如網頁、媒體播放器、圖片或外掛應用程式。以下是HTML中嵌入標籤的用法:

<embed attributes>

它沒有結束標籤。支援嵌入標籤的瀏覽器包括谷歌Chrome、Internet Explorer、Firefox、蘋果Safari和Opera。它支援HTML中的全域性和事件屬性。大多數瀏覽器都使用預設的CSS設定顯示<embed>元素,例如:

embed:focus {
   outline: none;
}

屬性

現在,讓我們看看支援“embed”標籤的屬性:

  • type − 在<embed>標籤中使用的type屬性定義檔案的MIME型別,這意味著它指定Internet媒體型別。

<embed type="media_type">      
  • src − 在<embed>標籤中使用的src屬性指定要嵌入的外部檔案的URL。

<embed src="URL">     
  • width − 在<embed>標籤中使用的width屬性定義物件的寬度。

<embed width="pixels">  
  • height − 在<embed>標籤中使用的height屬性定義物件的高度。

<embed height ="pixels">        

示例

以下示例演示如何在HTML5中新增外部(非HTML)應用程式的容器:

<!DOCTYPE html>
<html>
<head>
   <title> Add a container for an external (non-HTML) application in HTML5 </title>
   <style>
      q {
         color: red;
         font-style: italic;
      }
   </style>
</head>
<body>
   <br>
   <embed src="https://tutorialspoint.tw/images/logo.png?v2" type="image/jpg">
</body>
</html>

示例

以下是如何新增容器的另一個示例。在這裡,我們設定了容器的寬度和高度:

<!DOCTYPE html>
<html>
<body>
   <h1>Using embed text, src, height and width attributes</h1>
   <embed type="image/jpg" src="https://tutorialspoint.tw/images/english-tutorials_icon.svg" width="150" height="200">
</body>
</html>

示例

以下是如何在HML檔案中嵌入影片的示例:

<!DOCTYPE html>
<html>
<body>
   <h1> Sample Video embed into HTML File</h1>
   <embed type="video/webm" src="https://storage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" width="400" height="300">
</body>
</html>

示例

以下示例演示如何在原始檔中嵌入另一個HTML檔案:

<!DOCTYPE html>
<html>
<body>
   <h1>The embed element</h1>
   <embed type="text/html" src="https://tutorialspoint.tw/index.htm" width="500" height="200">
</body>
</html>

注意 −:要在網頁中顯示圖片,最好使用<img>標籤。要顯示HTML,最好使用<iframe>標籤。要顯示影片或音訊,最好使用<video><audio>標籤。

更新於:2023年10月6日

250 次瀏覽

啟動你的職業生涯

透過完成課程獲得認證

開始學習
廣告
© . All rights reserved.