<object>:外部对象元素

<object> HTML 元素表示外部资源,可以将其视为图片、嵌套浏览上下文或由插件处理的资源。

¥The <object> HTML element represents an external resource, which can be treated as an image, a nested browsing context, or a resource to be handled by a plugin.

Try it

属性

¥Attributes

该元素包括 全局属性

¥This element includes the global attributes.

archive Deprecated

用于对象资源存档的以空格分隔的 URI 列表。

border Deprecated

控件周围边框的宽度(以像素为单位)。

classid Deprecated

对象实现的 URI。它可以与数据属性一起使用,也可以代替数据属性。

codebase Deprecated

用于解析由 classid、data 或 archive 指定的相对 URI 的基本路径。如果未指定,则默认为当前文档的基本 URI。

codetype Deprecated

classid 指定的数据的内容类型。

data

作为有效 URL 的资源地址。必须至少定义数据和类型之一。

declare Deprecated

此布尔属性的存在使得该元素仅是一个声明。该对象必须由后续的 <object> 元素实例化。每次重用资源时,完全重复 <object> 元素。

form

与对象元素(其表单所有者)关联的表单元素(如果有)。该属性的值必须是同一文档中 <form> 元素的 ID。

height

显示资源的高度,单位为 CSS 像素。—(仅限绝对值。没有百分比

name

有效浏览上下文的名称 (HTML5) 或控件的名称 (HTML 4)。

standby Deprecated

浏览器在加载对象的实现和数据时可以显示的消息。

type

数据指定的资源的 内容类型。必须至少定义数据和类型之一。

usemap Deprecated

<map> 元素的哈希名称引用;这是一个 '' 后跟一个映射元素的 name 的值。

width

显示资源的宽度,单位为 CSS 像素。—(仅限绝对值。没有百分比

示例

¥Examples

嵌入视频

¥Embed a video

HTML

html
<object
  type="video/mp4"
  data="https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm"
  width="600"
  height="140">
  <img src="path/image.jpg" alt="useful image description" />
</object>

结果

¥Result

如果示例中的视频加载失败,将为用户提供图片作为后备内容。<img> 标签用于显示图片。我们将 src 属性设置为要嵌入的图片的路径。我们还包括 alt 属性,它为图片提供了一个可访问的名称。如果图片也加载失败,则会显示 alt 属性的内容。

¥If the video in the example fails to load, the user will be provided with an image as fallback content. The <img> tag is used to display an image. We include the src attribute set to the path to the image we want to embed. We also include the alt attribute, which provides the image with an accessible name. If the image also fails to load, the content of the alt attribute will be displayed.

技术总结

¥Technical summary

内容类别 流量内容; 措辞内容; 嵌入内容,可触及内容;如果元素具有 usemap 属性,则 互动内容; listed, submittable form-associated 元素。
允许的内容 零个或多个 <param> 元素,然后是 transparent
标签遗漏 无,开始和结束标记都是强制性的。
允许的父级 任何接受 嵌入内容 的元素。
隐式 ARIA 角色 没有对应的角色
允许的 ARIA 角色 application, document, img
DOM 接口 HTMLObjectElement

规范

Specification
HTML Standard
# the-object-element

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看

¥See also