object 要素

4.8.4 object 要素

カテゴリー
フロー・コンテンツ
フレージング・コンテンツ
エンベッディッド・コンテンツ
usemap 属性を持つ場合:インタラクティブ・コンテンツ
リストされ、サブミット可能フォーム関連要素
この要素を使うことができるコンテキスト:
エンベッディッド・コンテンツが期待される場所
コンテンツモデル:
0 個以上の param 要素。その次にトランスペアレント
コンテンツ属性:
グローバル属性
data
type
name
usemap
form
width
height
DOMインタフェース:
interface HTMLObjectElement : HTMLElement {
           attribute DOMString data;
           attribute DOMString type;
           attribute DOMString name;
           attribute DOMString useMap;
  readonly attribute HTMLFormElement form;
           attribute DOMString width;
           attribute DOMString height;
  readonly attribute Document contentDocument;
  readonly attribute WindowProxy contentWindow;

  readonly attribute boolean willValidate;
  readonly attribute ValidityState validity;
  readonly attribute DOMString validationMessage;
  boolean checkValidity();
  void setCustomValidity(in DOMString error);
};

object 要素によってインスタンスが生成されたコンテンツのタイプによって、このノードは他のインタフェースもサポートします。

object 要素は、外部のリソースを表すことができ、そのリソースのタイプによって、画像や、ネストされたブラウジング・コンテキストや、プラグインによって処理される外部リソース、のいずれかとして扱われます。

data 属性が存在すれば、それは、そのリソースのアドレスを指定します。指定する場合、この属性は潜在的にスペースで囲まれた空でない妥当な URL でなければいけません。

type 属性が存在すれば、それは、そのリソースのタイプを指定します。指定する場合、この属性は妥当な MIME タイプでなければいけません。

datatype 属性の少なくとも一方は存在しなければいけません。

name 属性が存在すれば、それは妥当なブラウジング・コンテキスト名でなければいけません。指定の値は、ネストされたブラウジング・コンテキストが適用できるのであれば、その名前に使われます。

この要素が生成され、HTML パーサーXML パーサー開いた要素のスタックから取り出される場合において、それに続いて、この要素がドキュメントに挿入されたり、ドキュメントから削除されるとき、そして、この要素の Document完全にアクティブかどうかが変わるとき、そして、祖先の object 要素がそのフォールバック・コンテンツの表示・非表示が変わるとき、そして、この要素の classid 属性がセット、変更、削除されるとき、そして、classid 属性が存在しない場合に data 属性がセット、変更、削除されるとき、そして、classid 属性も data 属性も存在しない場合に type 属性がセット、変更、削除されるとき:ユーザーエージェントは、その object 要素が何を表すのかを(再)決定するために次の手順を実行するタスクをキューイングしなければいけません。このタスクに対するタスク・ソースは、DOM マニュピュレーション・タスク・ソースです。

  1. If the user has indicated a preference that this object element's fallback content be shown instead of the element's usual behavior, then jump to the last step in the overall set of steps (fallback).

    For example, a user could ask for the element's fallback content to be shown because that content uses a format that the user finds more accessible.

  2. If the element has an ancestor media element, or has an ancestor object element that is not showing its fallback content, or if the element is not in a Document with a browsing context, or if the element's Document is not fully active, or if the element is still in the stack of open elements of an HTML parser or XML parser, then jump to the last step in the overall set of steps (fallback).

  3. If the classid attribute is present, and has a value that isn't the empty string, then: if the user agent can find a plugin suitable according to the value of the classid attribute, and plugins aren't being sandboxed, then that plugin should be used, and the value of the data attribute, if any, should be passed to the plugin. If no suitable plugin can be found, or if the plugin reports an error, jump to the last step in the overall set of steps (fallback).

  4. If the data attribute is present and its value is not the empty string, then:

    1. If the type attribute is present and its value is not a type that the user agent supports, and is not a type that the user agent can find a plugin for, then the user agent may jump to the last step in the overall set of steps (fallback) without fetching the content to examine its real type.

    2. Resolve the URL specified by the data attribute, relative to the element.

    3. If that failed, fire a simple event named error at the element, then jump to the last step in the overall set of steps (fallback).

    4. Fetch the resulting absolute URL, from the element's browsing context scope origin if it has one.

      Fetching the resource must delay the load event of the element's document until the task that is queued by the networking task source once the resource has been fetched (defined next) has been run.

      For the purposes of the application cache networking model, this fetch operation is not for a child browsing context (though it might end up being used for one after all, as defined below).

    5. If the resource is not yet available (e.g. because the resource was not available in the cache, so that loading the resource required making a request over the network), then jump to the last step in the overall set of steps (fallback). The task that is queued by the networking task source once the resource is available must restart this algorithm from this step. Resources can load incrementally; user agents may opt to consider a resource "available" whenever enough data has been obtained to begin processing the resource.

    6. If the load failed (e.g. there was an HTTP 404 error, there was a DNS error), fire a simple event named error at the element, then jump to the last step in the overall set of steps (fallback).

    7. Determine the resource type, as follows:

      1. Let the resource type be unknown.

      2. If the user agent is configured to strictly obey Content-Type headers for this resource, and the resource has associated Content-Type metadata, then let the resource type be the type specified in the resource's Content-Type metadata, and jump to the step below labeled handler.

      3. If there is a type attribute present on the object element, and that attribute's value is not a type that the user agent supports, but it is a type that a plugin supports, then let the resource type be the type specified in that type attribute, and jump to the step below labeled handler.

      4. Run the approprate set of steps from the following list:

        The resource has associated Content-Type metadata
        1. Let binary be false.

        2. If the type specified in the resource's Content-Type metadata is "text/plain", and the result of applying the rules for distinguishing if a resource is text or binary to the resource is that the resource is not text/plain, then set binary to true.

        3. If the type specified in the resource's Content-Type metadata is "application/octet-stream", then set binary to true.

        4. If binary is false, then let the resource type be the type specified in the resource's Content-Type metadata, and jump to the step below labeled handler.

        5. If there is a type attribute present on the object element, and its value is not application/octet-stream, then run the following steps:

          1. If the attribute's value is a type that a plugin supports, or the attribute's value is a type that starts with "image/" that is not also an XML MIME type, then let the resource type be the type specified in that type attribute.

          2. Jump to the step below labeled handler.

        The resource does not have associated Content-Type metadata
        1. If there is a type attribute present on the object element, then let the tentative type be the type specified in that type attribute.

          Otherwise, let tentative type be the sniffed type of the resource.

        2. If tentative type is not application/octet-stream, then let resource type be tentative type and jump to the step below labeled handler.

      5. If the <path> component of the URL of the specified resource (after any redirects) matches a pattern that a plugin supports, then let resource type be the type that that plugin can handle.

        For example, a plugin might say that it can handle resources with <path> components that end with the four character string ".swf".

      It is possible for this step to finish with resource type still being unknown, or for one of the substeps above to jump straight to the next step. In both cases, the next step will trigger fallback.

    8. Handler: Handle the content as given by the first of the following cases that matches:

      If the resource type is not a type that the user agent supports, but it is a type that a plugin supports

      If plugins are being sandboxed, jump to the last step in the overall set of steps (fallback).

      Otherwise, the user agent should use the plugin that supports resource type and pass the content of the resource to that plugin. If the plugin reports an error, then jump to the last step in the overall set of steps (fallback).

      If the resource type is an XML MIME type, or if the resource type does not start with "image/"

      The object element must be associated with a newly created nested browsing context, if it does not already have one.

      If the URL of the given resource is not about:blank, the element's nested browsing context must then be navigated to that resource, with replacement enabled, and with the object element's document's browsing context as the source browsing context. (The data attribute of the object element doesn't get updated if the browsing context gets further navigated to other locations.)

      If the URL of the given resource is about:blank, then, instead, the user agent must queue a task to fire a simple event named load at the object element.

      The object element represents the nested browsing context.

      If the name attribute is present, the browsing context name must be set to the value of this attribute; otherwise, the browsing context name must be set to the empty string.

      In certain situations, e.g. if the resource was fetched from an application cache but it is an HTML file with a manifest attribute that points to a different application cache manifest, the navigation of the browsing context will be restarted so as to load the resource afresh from the network or a different application cache. Even if the resource is then found to have a different type, it is still used as part of a nested browsing context: only the navigate algorithm is restarted, not this object algorithm.

      If the resource type starts with "image/", and support for images has not been disabled

      Apply the image sniffing rules to determine the type of the image.

      The object element represents the specified image. The image is not a nested browsing context.

      If the image cannot be rendered, e.g. because it is malformed or in an unsupported format, jump to the last step in the overall set of steps (fallback).

      Otherwise

      The given resource type is not supported. Jump to the last step in the overall set of steps (fallback).

      If the previous step ended with the resource type being unknown, this is the case that is triggered.

    9. The element's contents are not part of what the object element represents.

    10. Once the resource is completely loaded, queue a task to fire a simple event named load at the element.

      The task source for this task is the DOM manipulation task source.

  5. If the data attribute is absent but the type attribute is present, plugins aren't being sandboxed, and the user agent can find a plugin suitable according to the value of the type attribute, then that plugin should be used. If no suitable plugin can be found, or if the plugin reports an error, jump to the next step (fallback).

  6. (Fallback.) The object element represents the element's children, ignoring any leading param element children. This is the element's fallback content. If the element has an instantiated plugin, then unload it.

上記のアルゴリズムがプラグインのインスタンスを生成するとき、ユーザーエージェントは、その要素上のすべての属性の名前と値を、それらがその要素に追加された順番で、パーサーによってソース順に並べて追加された属性を使って、そのプラグインに引き渡すべきです。加えて、値が null となる "PARAM" という名前のパラメータ、その次に、該当の object 要素の子となる param 要素に指定されたパラメータの名前と値がツリー順に続きます。プラグインがスクリプトのインタフェースをサポートしているなら、該当の要素を表している HTMLObjectElement オブジェクトから、そのインタフェースにアクセスできるようにするべきです。object 要素はプラグイン表します。そのプラグインはネストされたブラウジング・コンテキストではありません。

以下のいずれかの場合:

... 上記いずれかなら、プラグインが使われていたとしても、上記の手順は、プラグインの発見に失敗したかのように動作しなければいけません。

前述のアルゴリズムは CSS プロパティ(display', 'overflow', 'visibility' を含む)とは無関係です。例えば、この要素が display:none' CSS スタイルによって非表示だとしても、実行されます。この要素の表示・非表示が変わっても、再実行されることはありません。

上記のアルゴリズムによって、object 要素のコンテンツは、参照リソースを表示することができないとき(例えば、404 エラーを返すなどの理由で)に限り、フォールバック・コンテンツの役割を果たします。こうすることで、object 要素をどれだけでも深くネストすることができるようになり、機能が違うユーザーエージェントをいくつもターゲットとすることができるようになります。ユーザーエージェントは、そのうち、自身がサポートしている最初のものを採用することになります。

name 属性がセットされたらいつでも、object 要素がネストされたブラウジング・コンテキストを持つなら、その名前は新しい値に変更されなければいけません。この属性が削除され、object 要素がブラウジング・コンテキストを持つなら、そのブラウジング・コンテキスト名は、空文字列にセットされなければいけません。

object 要素が画像を表す場合 に usemap 属性が存在すれば、それは、その object 要素が関連するイメージマップを持つことを意味することができます。この属性は、object 要素が画像を表さない場合は、無視されなければいけません。

form 属性は、明示的にその object 要素をフォーム・オーナーに結びづけるために使われます。

制約バリデーション:object 要素は常に、制約バリデーションから除外されます。

object 要素はディメンジョン属性をサポートします。

IDL 属性 data, type, name, useMap はそれぞれ、同じ名前の対応するコンテンツ属性を反映しなければいけません。

contentDocument IDL 属性は、object 要素のネストされたブラウジング・コンテキストアクティブ・ドキュメントがあれば、その Document オブジェクトを返さなければいけません。なければ null を返さなければいけません。

contentWindow IDL 属性は、object 要素のネストされたブラウジング・コンテキストがあれば、その WindowProxy オブジェクトを返さなければいけません。なければ null を返さなければいけません。

willValidate, validity, validationMessage 属性、そして、checkValidity(), setCustomValidity() メソッドは、制約バリデーション API の一部となります。 form IDL 属性は、この要素の forms API の一部となります。

次の例では、Javaアプレットが object 要素を使ってページに組み込まれています。(一般的にいえば、このようなアプレットの利用を避け、代わりに、ネイティブのJavaScriptとHTMLを機能提供のために使う方が良いでしょう。こうすることで、サードパーティのプラグインを要求せずとも、すべてのブラウザでこのアプリケーションが動作するでしょう。多くのデバイス、とりわけ組込デバイスは、Javaといったサードパーティ製テクノロジーをサポートしていません。)

<figure>
 <object type="application/x-java-applet">
  <param name="code" value="MyJavaClass">
  <p>You do not have Java available, or it is disabled.</p>
 </object>
 <figcaption>My Java Clock</figcaption>
</figure>

この例では、一方のHTMLページが、もう一方のページから object 要素を使って組み込まれています。

<figure>
 <object data="clock.html"></object>
 <figcaption>My HTML Clock</figcaption>
</figure>

次の例は、どのようにして プラグインを HTML の中で使うことができるのかを示しています(ここでは、ビデオ・ファイルを見せるために、Flash プラグインを使います)。Flash が組み込んでいないユーザーには、フォールバックを提供しています。ここでは、video 要素をサポートしているユーザーエージェントを使っているユーザーに対しては video 要素を使ってビデオを見せるようにしています。そして、さらに、Flash も video 未対応ブラウザーもないユーザーに対しては、ビデオへのリンクを提供しています。

<p>Look at my video:
 <object type="application/x-shockwave-flash">
  <param name=movie value="http://video.example.com/library/watch.swf">
  <param name=allowfullscreen value=true>
  <param name=flashvars value="http://video.example.com/vids/315981">
  <video controls src="http://video.example.com/vids/315981">
   <a href="http://video.example.com/vids/315981">View video</a>.
  </video>
 </object>
</p>

※ 原文:http://www.w3.org/TR/2011/WD-html5-20110525/the-iframe-element.html#the-object-element