|
前页|后页| 目录|元素| 特性 容器目录
下面的章节描述了由HTML提供的用于在文档中包含一个
资?源的不同的结构.HTML允许作者包含物件,
图像,小运行程式,
文件和图像映像.
包含一个物件:OBJECT 元素<!ENTITY % OAlign "(texttop|middle|textmiddle|baseline| textbottom|left|center|right)"> <!ELEMENT OBJECT - - (PARAM | %block)*> <!ATTLIST OBJECT ?%attrs --%coreattrs,%i18n,%events -- declare (declare)?#IMPLIED?--declare but don't instantiate flag -- classid %URL #IMPLIED?--identifies an implementation -- codebase ?%URL #IMPLIED?--some systems need an additional URL-- data ?%URL #IMPLIED?--reference to object's data -- type %ContentType #IMPLIED?--Internet content type for data -- codetype%ContentType #IMPLIED?--Internet content type for code -- standby CDATA ?#IMPLIED?--message to show while loading -- align %OAlign ?#IMPLIED?--positioning inside document -- height ?%Length ?#IMPLIED?--suggested height -- width %Length ?#IMPLIED?--suggested width -- border ?%Length ?#IMPLIED?--suggested link border width -- hspace ?%Length ?#IMPLIED?--suggested horizontal gutter -- vspace ?%Length ?#IMPLIED?--suggested vertical gutter -- usemap ?%URL #IMPLIED?--reference to image map -- shapes ?(shapes) #IMPLIED?--object has shaped hypertext links -- name ?%URL #IMPLIED?--submit as part of form -- tabindex NUMBER #IMPLIED?-- position in tabbing order -- ?>开始标记:需要,结束标记:需要 特性定义
在它处定义的特性
大多数用户代理器包含对常规数据形式如文本,GIF图像,
颜色,字体和可控图像元素的渲染信息.为了渲染它们天
生不提供的数据形式,用户代理器通常运行外部程式.OBJECT
元素允许作者来控制用户代理器在内客还是外部处理包
含的物件.
? 在大多数通常的情况下,一个插入的渲染结构指定了 信息的三种形式: ?
在HTML中,OBJECT 元素指定了渲染结构的位置以及渲染结构需的数据的位 置.这些特性通过OBJECT 元素的信息来指定.PARAM 元素指一个动行态值的集.我们在后面研究这个元素,在 物件初始化部分. 一个用户代理器必须根据下列的优先权法则来解译OBJECT 元素:
在下面的例?程中,我们插入了一个虚构的
以Python (大蟒)语言写的渲染结构来显示一个电脑时钟.这
个可通行程?式无需额外的数据和运行态值.classid
特性指定小运行程式的位置:
一个OBJECT元素定
义的重要影响是指明交互物件的渲染结构;每个绑定的OBJECT
声明指定一个交互渲染结构.如果一个用户代理器无法渲
染一个外部OBJECT,
它尝试渲染它的内容,可以是另一个OBJECT
元素等.
<OBJECT classid="http://www.miamachina.it/analogclock.py"> </OBJECT>我们建议通过包含OBJECT 内容中的交互文字来完成这个声明.此例中用户代理器无 法渲染这个钟. <OBJECT classid="http://www.miamachina.it/analogclock.py"> An animated clock. </OBJECT>注意用户代理器将在解译OBJECT 声明的同时渲染这个种.在物件第一次声明时渲染结构可 能会延迟(在下描述). 在下面的例程中,我们嵌入数个OBJECT
声明来举例说明渲染工作.用户代理器将尝?试渲?染它能够
的第一个OBJECT元
素,通过下面的次序:(1)一个用Python (大蟒)语言写的地球
小运行程式,(2)一个地球的MPEG动画,(3)一个地球的GIF图
像,(4)交互文本
<OBJECT title="The Earth as seen from space" classid="http://www.observer.mars/TheEarth.py"> <OBJECT data="TheEarth.mpeg" type="application/mpeg"> ? <OBJECT src="TheEarth.gif"> The <STRONG>Earth</STRONG> as seen from space. ? </OBJECT> </OBJECT> </OBJECT>外部声明指定一个小运行程式不需要数据和初始值.第二 个声明指明一个MPEG电影并且由于没有定义一个渲染结 构,它依靠用户代理器来处理这个动画.我们还设置了type 特性因此用户代理器可以选择不从网路上取回"TheEarth.mpeg" 也不渲染它.第三个指定指定了?GIF文件的位置以及当所 的的结构失败时的交互文本. 内层与外部数据的比较.被渲
染的数据可以通过两种途径来指定:内层和和来自于外部
资源的.形成方法通常将引起更快速?的渲染,但在渲染大
量数据时却是不相宜的.
物件初始化:?A NAME="edef-PARAM">PARAM 元素<!ELEMENTPARAM - O EMPTY -- named property value --> <!ATTLIST PARAM name ?CDATA ?#REQUIRED--property name -- value CDATA ?#IMPLIED?--property value -- valuetype(DATA|REF|OBJECT)DATA--How to interpret value -- type ?CDATA ?#IMPLIED?-- Internet media type -- ?>开始标记:需要,结束标记:禁止 特性定义
我们回到我们的钟例程.这次,我们假定
渲染机制(钟)能够处理两个定义初始高度和宽度的运行
态参数.我们通过初始的两个PARAM
元素来设定一个40x40的长方形.
<OBJECT classid="http://www.miamachina.it/analogclock.py"> <PARAM name="height" value="40" valuetype="data"> <PARAM name="width" value="40" valuetype="data"> This user agent cannot render Python apps. </OBJECT>Since the default valuetype for a PARAMelement is "data",we could replace the above declarations with either: ? <PARAM name="height" value="40"> <PARAM name="width" value="40" >or: ? <PARAM name="height" value="40" data> <PARAM name="width" value="40"?data>(The latter form --the value "data"only for valuetype attribute --is possible due to the DTDdefinition of this attribute.) In the following example,run-time data for the rendering
mechanism's "Init_values"parameter is specified as an external resource
(a GIFfile).The value of the valuetype
attribute is thus set to "ref",and the valueis a URLdesignating
the resource.
Rendering mechanisms are located by URLs.As we discussed in the section
on URLs,the first segment of an
absolute URLspecifies the protocol used to transfer the data designated
by the URL.For HTMLdocuments,this protocol is generally "http".Some
rendering mechanisms might employ other protocols.For instance,when specifying
a Java rendering mechanism,you may use URLs that begin with "java"and
for ActiveXapplets,you may use "clsid".
<OBJECT classid="http://www.gifstuff.com/gifappli" standby="Loading Elvis..."> <PARAM name="Init_values" value="./images/elvis.gif"> valuetype="ref"> </OBJECT>Note that we have also set the standby attribute so that the user agent may render a message while the rendering mechanism loads. In the following example,we insert a Java applet
into an HTMLdocument.
<OBJECT classid="java:program.start"> </OBJECT>By setting the codetype attribute,a user agent can decide whether to retrieve the Java application based on its ability to do so. <OBJECT codetype="application/octet-stream" classid="java:program.start"> </OBJECT>Some rendering schemes require additional information to identify their implementation and must be told where to find that information.You may give path information to the rendering mechanism via the codebase attribute. <OBJECT codetype="application/octet-stream" classid="java:program.start"> codebase="http://foooo.bar.com/java/myimplementation/" </OBJECT> The following example specifies (with the classid
attribute)an ActiveXrendering mechanism via a URLthat begins with the
protocol information "clsid".The data
attribute locates the data to render (another clock).
<OBJECT classid="clsid:663C8FEF-1EF9-11CF-A3DB-080036F12502" data="http://www.acme.com/ole/clock.stm"> This application is not supported. </OBJECT> Object declarations and instantiationsThe preceding examples have only illustrated isolated object definitions. When a document is to contain more than one instance of the same object, it is possible to separate the declaration of the object from its instantiations. Doing so has several advantages:
Arendering mechanism defined with the declare attribute is instantiated every time the OBJECT is referenced thereafter. In the following example,we declare an OBJECT
and cause it so be instantiated by referring to it from a link.Thus,the
object can be activated by clicking on some highlighted text,for example.
<OBJECT declare id="earth_declaration"? data="TheEarth.mpeg"? type="application/mpeg"> <OBJECT src="TheEarth.gif"> The <STRONG>Earth</STRONG> as seen from space. ?</OBJECT> </OBJECT> ...later in the document... Click to see a neat <A href="#earth_declaration"> animation of The Earth!</A> The following example illustrates how to specify run-time
values that are other objects.In this example,we send text (a poem,in
fact)to a hypothetical mechanism for viewing poems.The rendering mechanism
recognizes a run-time parameter named "font"(say,for rendering the poem
text in a certain font).The value for this parameter is itself an object
that inserts (but does not render)the font object.The relationship between
the font object and the poem viewer object is achieved by (1)assigning
the id"tribune"to the font
object declaration and (2)referring to it from the PARAM
element of the poem viewer object (with valuetype
and value).
User agents that don't support the declare
attribute must render the contents of the OBJECT
declaration.
<OBJECT declare id="tribune" type="application/x-webfont" data="tribune.gif"> </OBJECT> ...view the poem in KublaKhan.txt here... <OBJECT classid="http://foo.bar.com/poem_viewer"? data="KublaKhan.txt"> <PARAM name="font" valuetype="object" value="#tribune"> <P>You're missing a really cool poem viewer ... </OBJECT> Object alignmentThe alignattribute has been deprecated for this element in favor of style sheets.The alignattribute specifies the position of an object with respect to its context. The following values place an object in the heart of text:
Including an image: the?A NAME="edef-IMG">IMG element<!-- To avoid problems with text-only UAs you need to provide a description with ALT, and avoid server-side image maps --> <!ELEMENTIMG - O EMPTY ?--?Embedded image --> <!ATTLIST IMG ?%attrs; ?--%coreattrs,%i18n,%events -- src %URL #REQUIRED--URLof image to embed -- alt CDATA ?#IMPLIED?--description for text only browsers -- align %IAlign ?#IMPLIED?--vertical or horizontal alignment -- height ?%Pixels ?#IMPLIED?--suggested height in pixels -- width %Pixels ?#IMPLIED?--suggested width in pixels -- border ?%Pixels ?#IMPLIED?--suggested link border width -- hspace ?%Pixels ?#IMPLIED?--suggested horizontal gutter -- vspace ?%Pixels ?#IMPLIED?--suggested vertical gutter -- usemap ?%URL #IMPLIED?--use client-side image map -- ismap (ismap) ?#IMPLIED?-- use server-side image map -- ?>Start tag:required,End tag:forbidden Attribute definitions
Attributes defined elsewhere
The IMGelement embeds an
image in the current document at the location of the element's definition.
However,we recommend using the OBJECT
element to insert an image into a document.
The heightand widthattributes of this element override the natural height and width of the source image.User agents should scale the image appropriately. In an earlier example,we defined a link to a family
photo.Here,we insert the photo directly into the current document
The altattribute specifies
alternate text when the image cannot be displayed (see below for information
on how to specify alternate text).
...preceding text... I just returned from vacation! Here's a photo of my family at the lake: <IMG src="http://www.somecompany.com/People/Ian/vacation/family.png" alt="A photo of my family at the lake.">This may be expressed with the OBJECT element as follows: ...preceding text... I just returned from vacation! Here's a photo of my family at the lake: <OBJECT data="http://www.somecompany.com/People/Ian/vacation/family.png" type="image/png"> A photo of my family at the lake. </OBJECT> Image alignmentThe alignattribute has been deprecated for this element in favor of style sheets.The alignattribute specifies the position of an object with respect to its context. The following values place an object in the heart of text:
Differing interpretations of align.
Existing user agents vary in their interpretation of the align
attribute.Some only take into account what has occurred on the text line
prior to the element,some take into account the text on both sides of
the element.
Including an applet: the?A NAME="edef-APPLET">APPLET elementAPPLETis deprecated.<!ELEMENTAPPLET - - (PARAM | %inline)*> <!ATTLIST APPLET codebase ?%URL #IMPLIED --optional base URLfor applet -- archive CDATA ?#IMPLIED --comma separated archive list -- code ?CDATA ?#IMPLIED --applet class file -- object ?CDATA ?#IMPLIED --serialized applet file -- alt CDATA ?#IMPLIED --description for text only browsers -- name ?CDATA ?#IMPLIED --allows applets to find each other -- width %Pixels ?#REQUIRED?--suggested width in pixels -- height ?%Pixels ?#REQUIRED?--suggested height in pixels -- align %IAlign ?#IMPLIED --vertical or horizontal alignment -- hspace ?%Pixels ?#IMPLIED --suggested horizontal gutter -- vspace ?%Pixels ?#IMPLIED -- suggested vertical gutter -- ?>Start tag:required,End tag:required Attribute definitions
Attributes defined elsewhere
This element,supported by all Java-enabled browsers,allows designers
to embed a Java applet in an HTMLdocument.It has been deprecated in favor
of the OBJECTelement.
The content of the APPLET acts as alternate information for user agents that don't support this element or are currently configured not to support applets.The content must be ignored otherwise. The following sample Java applet:
Initial values may be supplied to the applet via the PARAM
element.
<APPLET code="Bubbles.class" width="500px" height="500px"> Java applet that draws animated bubbles. </APPLET>may be rewritten as follows with OBJECT: <OBJECT codetype="application/octet-stream" classid="java:Bubbles.class" width="500" height="500px"> Java applet that draws animated bubbles. </OBJECT> The following sample Java applet:
<APPLET code="AudioItem" width="15px" height="15px"> <PARAM name="snd" value="Hello.au|Welcome.au"> Java applet that plays a welcoming sound. </APPLET>may be rewritten as follows with OBJECT: <OBJECT codetype="application/octet-stream" classid="AudioItem" width="15" height="15px"> <PARAM name="snd" value="Hello.au|Welcome.au"> Java applet that plays a welcoming sound. </OBJECT> Including HTMLin another HTMLdocumentSometimes,rather than linking to another document,it is helpful to include the contents of an HTMLdocument in another HTMLdocument.We recommend using the OBJECTelement with the dataattribute for this purpose.For instance,the following line will include the
contents of piece_to_include.htmlat the location where the OBJECT
definition occurs.
The behavior of a user agent in cases where a file includes itself is not
defined.
...text before... <OBJECT data="file_to_include.html"> Warning: file_to_include.html could not be included. </OBJECT> ...text after...The contents of OBJECT must only be rendered if the file specified by the data attribute cannot be loaded. Careful file inclusions.Be careful if you
attempt to include a section of an HTMLdocument defined by an anchor.
The entire document after the anchor definition will be included,and you
might unwittingly include unwanted end tags (for elements such as BODY,
HTML,etc.)in your document.
The IFRAMEelement
may also be used to insert an inline frame containing text in an HTMLdocument.
Including an image map in an HTMLdocumentAn image map allows users authors to specify active regions of an image or object and assign a specific action to each region (e.g.,retrieve a document,run a program,etc.)An image map is created by associating an object with a specification of sensitive geometric areas on the object. There are two types of image maps:
Non-graphical representation of image maps.
Non-graphical user agents may render client-side image maps as sets of
textual links.The textual region may be activated by keyboard input.
Client-side image mapsThe following attributes are defined for several elements (A and AREA).They allow authors to specify a set of geometrical regions and associate URLs with them.Attribute definitions
The following attribute is defined for the OBJECT
element.
Attribute definitions
In the following example,we create a client-side
image map for the OBJECT
element by associating URLs with regions specified by a series of A
elements.
If the OBJECTelement
includes a shapesattribute,
user agents must parse the contents of the element to look for anchors.
<OBJECT data="navbar.gif" shapes> <A href="guide.html" shape="rect" coords="0,0,118,28">Access Guide </a> | <A href="shortcut.html" shape="rect" coords="118,0,184,28">Go </A> | <A href="search.html" shape="circ" coords="184,200,60">Search </A> | <A href="top10.html" shape="poly" coords="276,0,373,28,50,50,276,0">Top Ten </A> </OBJECT> If two or more defined regions overlap,the region defined first takes precedence (i.e.,responds to user input). Client-side image maps with?A NAME="edef-MAP">MAP and?A NAME="edef-AREA">AREAThe MAPand AREA elements provide an alternate mechanism for client side image maps.<!ELEMENTMAP - - (AREA)*> <!ATTLIST MAP %coreattrs; --id, class,style,title-- name ?CDATA #IMPLIED ?>Start tag:required,End tag:required <!ELEMENTAREA - O EMPTY> <!ATTLIST AREA shape %Shape ?rect ?--controls interpretation of coords -- coords ?%Coords #IMPLIED?--comma separated list of values -- href ?%URL ?#IMPLIED?--this region acts as hypertext link -- target ?CDATA #IMPLIED?--where to render linked resource --? nohref ?(nohref)?#IMPLIED?--this region has no action -- alt CDATA #REQUIRED--description for text only browsers -- tabindex ?NUMBER ?#IMPLIED?-- position in tabbing order -- ?>Start tag:required,End tag:forbidden Attribute definitions
Attributes defined elsewhere
Several elements (OBJECT,
IMG,and INPUT)
allow the following attribute to specify an associated client-side image
map.
Attribute definitions
We can rewrite the previous example in terms of MAP
and AREA.We still create
an OBJECTthat will insert
an image.We associate the object and the image map by setting the usemap
attribute on the OBJECT
and the nameattribute of the MAP
element to the same value.
<OBJECT data="navbar1.gif" usemap="#map1"></OBJECT> <MAP name="map1"> <AREA href="guide.html"? alt="Access Guide"? ?shape="rect"? ?coords="0,0,118,28"> <AREA href="search.html"? ?alt="Search"? ?shape="rect"? ?coords="184,0,276,28"> <AREA href="shortcut.html"? ?alt="Go"? ?shape=circ? ?coords="184,200,60"> <AREA href="top10.html"? alt="Top Ten"? ?shape="poly"? coords="276,0,373,28,50,50,276,0"> </MAP>The altattribute specifies alternate text for cases when the image map may not be displayed (see below for information on how to specify alternate text). Note:MAP
is not backwards compatible with HTML2.0user agents.
Server-side image mapsServer-side image maps may be interesting in cases where the image map is too complicated for a client-side image map.It is only possible to define a server-side image map with the IMG element. To do so, set the boolean attributeismap in the IMGdefinition.The associated map of regions must be specified with the usemap attribute. When the user activates a region of the image map,the screen coordinates are sent directly to the server where the document resides.Screen coordinates are expressed as screen pixel values.For normative information about the definition of a pixel and how to scale it,please consult [CSS1]. The location clicked is passed to the server as follows.The user agent derives a new URLfrom the URLspecified by the href attribute by appending `?'followed by the x and y coordinates,separated by a comma.The link is then followed using the new URL.For instance, in the previous example,if the user clicks at at the location x=10,y=27 then the derived URLis "/cgibin/navbar.map?10,27". In the following example,the first active region
defines a client-side link.The second defines a server-side link,but
doesn't assign a specific shape to it (this is accomplished with the "default"
value of the shapeattribute).
Since the regions of the two links overlap,the first takes precedence
of the later definition.Thus,a click anywhere but in the rectangle will
cause the click's coordinates to be sent to the server.
<OBJECT data="game.gif" shapes> ?<A href="guide.html" shape="rect" coords="0,0,118,28"> Rules of the Game</A> <A href="http://www.acme.com/cgi-bin/competition" ?ismap? ?shape="default"> Guess the location</a> </OBJECT> Visual presentation of images,objects,and appletsAll IMGand OBJECT attributes that concern visual alignment or presentation have been deprecated in favor of style sheets.The heightand widthattributes give user agents an idea of the size of an image or object so that they may reserve space for it and continue rendering the document while waiting for the image data. Both attributes take values of type length. User agents may scale objects and images to match these values if appropriate. The vspaceand hspaceattributes specify the amount of white space to be inserted to the left and right (hspace)and above and below (vspace)an image or object.The default value for this attribute is not specified,but is generally a small,non-zero length.Both attributes take values of type length. Images or objects that are the content of an A element are sometimes surrounded by a border.The border attribute specifies the width of this border. How to specify alternate textAttribute definitions
Several non-textual elements (IMG,
AREA,APPLET,
and INPUT)allow
authors to specify alternate text to serve as content when the element
cannot be rendered normally.Specifying alternate text assists users without
graphic display terminals,users whose browsers don't support forms,visually
impaired users,those who use speech synthesizers,those who have configured
their graphical user agents not to display images,etc.
While alternate text may be very helpful,it must be handled with care. Authors should observe the following guidelines:
When an author does not set the alt attribute for the IMGor APPLETelements,user agents should supply the alternate text,calculated in the following order:
|