Movatterモバイル変換


[0]ホーム

URL:


 previous next  contents  elements  attributes  index

16 Frames

Contents

  1. Introduction to frames
  2. Layout of frames
    1. TheFRAMESET element
    2. TheFRAMEelement
  3. Specifying target frame information
    1. Setting the default target forlinks
    2. Target semantics
  4. Alternate content
    1. TheNOFRAMES element
    2. Long descriptions of frames
  5. Inline frames: theIFRAME element

16.1Introduction toframes

HTML frames allow authors to present documents in multiple views, which maybe independent windows or subwindows. Multiple views offer designers a way tokeep certain information visible, while other views are scrolled or replaced.For example, within the same window, one frame might display a static banner, asecond a navigation menu, and a third the main document that can be scrolledthrough or replaced by navigating in the second frame.

Here is a simple frame document:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"   "http://www.w3.org/TR/html4/frameset.dtd"><HTML><HEAD><TITLE>A simple frameset document</TITLE></HEAD><FRAMESET cols="20%, 80%">  <FRAMESET rows="100, 200">      <FRAME src="contents_of_frame1.html">      <FRAME src="contents_of_frame2.gif">  </FRAMESET>  <FRAME src="contents_of_frame3.html">  <NOFRAMES>      <P>This frameset document contains:      <UL>         <LI><A href="contents_of_frame1.html">Some neat contents</A>         <LI><IMG src="contents_of_frame2.gif" alt="A neat image">         <LI><A href="contents_of_frame3.html">Some other neat contents</A>      </UL>  </NOFRAMES></FRAMESET></HTML>

that might create a frame layout something like this:

 ---------------------------------------|         |                             ||         |                             || Frame 1 |                             ||         |                             ||         |                             ||---------|                             ||         |          Frame 3            ||         |                             ||         |                             ||         |                             || Frame 2 |                             ||         |                             ||         |                             ||         |                             ||         |                             | ---------------------------------------

If the user agent can't display frames or is configured not to, it willrender the contents of theNOFRAMES element.

16.2 Layout of frames

An HTML document that describes frame layout (called aframeset document) has a different makeup than an HTMLdocument without frames. A standard document has oneHEAD section and oneBODY. A frameset document has aHEAD, and aFRAMESET in place of theBODY.

TheFRAMESET section of a document specifies the layout of views in themain user agent window. In addition, theFRAMESET section can contain aNOFRAMES element to providealternatecontent for user agents that do not support frames or are configured not todisplay frames.

Elements that might normally be placed in theBODY element must not appear before the firstFRAMESET element or theFRAMESET will be ignored.

16.2.1 TheFRAMESET element

<![%HTML.Frameset; [<!ELEMENTFRAMESET - - ((FRAMESET|FRAME)+ & NOFRAMES?) -- window subdivision--><!ATTLIST FRAMESET%coreattrs;                          --id,class,style,title --rows%MultiLengths; #IMPLIED  -- list of lengths,                                          default: 100% (1 row) --cols%MultiLengths; #IMPLIED  -- list of lengths,                                          default: 100% (1 col) --onload%Script;       #IMPLIED  -- all the frames have been loaded  --onunload%Script;       #IMPLIED  -- all the frames have been removed --   >]]>

Attribute definitions

rows =multi-length-list[CN]
This attribute specifies the layout of horizontal frames. It is acomma-separated list of pixels, percentages, and relative lengths. The defaultvalue is 100%, meaning one row.
cols =multi-length-list[CN]
This attribute specifies the layout of vertical frames. It is acomma-separated list of pixels, percentages, and relative lengths. The defaultvalue is 100%, meaning one column.

Attributes defined elsewhere

TheFRAMESET element specifies the layout of the main userwindow in terms of rectangular subspaces.

Rows and columns 

Setting therows attribute defines the number ofhorizontal subspaces in a frameset. Setting thecols attribute defines the number of vertical subspaces. Bothattributes may be set simultaneously to create a grid.

If therows attribute is not set, each column extends theentire length of the page. If thecols attribute is notset, each row extends the entire width of the page. If neither attribute isset, the frame takes up exactly the size of the page.

Frames are created left-to-right for columns and top-to-bottom for rows.When both attributes are specified, views are created left-to-right in the toprow, left-to-right in the second row, etc.

The first example divides the screen vertically in two (i.e., creates a tophalf and a bottom half).

<FRAMESET rows="50%, 50%">...the rest of the definition...</FRAMESET>

The next example creates three columns: the second has a fixed width of 250pixels (useful, for example, to hold an image with a known size). The firstreceives 25% of the remaining space and the third 75% of the remainingspace.

<FRAMESET cols="1*,250,3*">...the rest of the definition...</FRAMESET>

The next example creates a 2x3 grid of subspaces.

<FRAMESET rows="30%,70%" cols="33%,34%,33%">...the rest of the definition...</FRAMESET>

For the next example, suppose the browser window is currently 1000 pixelshigh. The first view is allotted 30% of the total height (300 pixels). Thesecond view is specified to be exactly 400 pixels high. This leaves 300 pixelsto be divided between the other two frames. The fourth frame's height isspecified as "2*", so it is twice as high as the third frame, whose height isonly "*" (equivalent to 1*). Therefore the third frame will be 100 pixels highand the fourth will be 200 pixels high.

<FRAMESET rows="30%,400,*,2*">...the rest of the definition...</FRAMESET>

Absolute lengths that do not sum to 100% of the real available space shouldbe adjusted by the user agent. When underspecified, remaining space should beallotted proportionally to each view. When overspecified, each view should bereduced according to its specified proportion of the total space.

Nested frame sets 

Framesets may be nested to any level.

In the following example, the outerFRAMESET divides the availablespace into three equal columns. The innerFRAMESET then divides the secondarea into two rows of unequal height.

<FRAMESET cols="33%, 33%, 34%">...contents of first frame...     <FRAMESET rows="40%, 50%">...contents of second frame, first row......contents of second frame, second row...     </FRAMESET>...contents of third frame...</FRAMESET>

Sharing data among frames 

Authors may share data among several frames by including this data via anOBJECT element. Authors should include theOBJECT element in theHEAD element of a framesetdocument and name it with theid attribute. Any document that is thecontents of a frame in the frameset may refer to this identifier.

The following example illustrates how a script might refer to anOBJECT element defined for an entire frameset:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"   "http://www.w3.org/TR/html4/frameset.dtd"><HTML><HEAD><TITLE>This is a frameset with OBJECT in the HEAD</TITLE><!-- This OBJECT is not rendered! --><OBJECT data="data.bar"></OBJECT></HEAD><FRAMESET>    <FRAME src="bianca.html" name="bianca"></FRAMESET></HTML><!-- In bianca.html --><HTML><HEAD><TITLE>Bianca's page</TITLE></HEAD><BODY>...the beginning of the document...<P><SCRIPT type="text/javascript">parent.myobject.myproperty</SCRIPT>...the rest of the document...</BODY></HTML>

16.2.2 TheFRAME element

<![%HTML.Frameset; [<!-- reserved frame names start with "_" otherwise starts with letter --><!ELEMENTFRAME - O EMPTY              -- subwindow --><!ATTLIST FRAME%coreattrs;                          --id,class,style,title --longdesc%URI;          #IMPLIED  -- link to long description                                          (complements title) --nameCDATA          #IMPLIED  -- name of frame for targetting --src%URI;          #IMPLIED  -- source of frame content --frameborder (1|0)          1         -- request frame borders? --marginwidth%Pixels;       #IMPLIED  -- margin widths in pixels --marginheight%Pixels;      #IMPLIED  -- margin height in pixels --noresize    (noresize)     #IMPLIED  -- allow users to resize frames? --scrolling   (yes|no|auto)  auto      -- scrollbar or none --  >]]>

Attribute definitions

name =cdata[CI]
This attribute assigns a name to the current frame. This name may be usedas the target of subsequent links.
longdesc =uri[CT]
This attribute specifies a link to a long description of the frame. Thisdescription should supplement the short description provided using thetitle attribute, and may be particularly useful for non-visual useragents.
src =uri[CT]
This attribute specifies the location of the initial contents to becontained in the frame.
noresize[CI]
When present, this boolean attribute tells the user agent that the framewindow must not be resizeable.
scrolling =auto|yes|no[CI]
This attribute specifies scroll information for the frame window. Possiblevalues
  • auto: This value tells the user agent to provide scrollingdevices for the frame window when necessary. This is the default value.
  • yes: This value tells the user agent to always providescrolling devices for the frame window.
  • no: This value tells the user agent not to provide scrollingdevices for the frame window.
frameborder =1|0[CN]
This attribute provides the user agent withinformation about the frame border. Possible values:
  • 1: This value tells the user agent to draw a separator betweenthis frame and every adjoining frame. This is the default value.
  • 0: This value tells the user agent not to draw a separatorbetween this frame and every adjoining frame. Note that separators may be drawnnext to this frame nonetheless if specified by other frames.
marginwidth =pixels[CN]
This attribute specifies theamount of space to be left between the frame's contents in its left and rightmargins. The value must be greater than zero (pixels). The default valuedepends on the user agent.
marginheight =pixels[CN]
This attribute specifies the amount of space to be left between the frame'scontents in its top and bottom margins. The value must be greater than zero(pixels). The default value depends on the user agent.

Attributes defined elsewhere

TheFRAME element defines the contents and appearance of a singleframe.

Setting the initial contents of a frame 

Thesrc attribute specifies the initial document the frame willcontain.

The following example HTML document:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"   "http://www.w3.org/TR/html4/frameset.dtd"><HTML><HEAD><TITLE>A frameset document</TITLE></HEAD><FRAMESET cols="33%,33%,33%">  <FRAMESET rows="*,200">      <FRAME src="contents_of_frame1.html">      <FRAME src="contents_of_frame2.gif">  </FRAMESET>  <FRAME src="contents_of_frame3.html">  <FRAME src="contents_of_frame4.html"></FRAMESET></HTML>

should create a frame layout something like this:

 ------------------------------------------|Frame 1     |Frame 3       |Frame 4       ||            |              |              ||            |              |              ||            |              |              ||            |              |              ||            |              |              ||            |              |              ||            |              |              |-------------|              |              ||Frame 2     |              |              ||            |              |              ||            |              |              | ------------------------------------------

and cause the user agent to load each file into a separate view.

The contents of a frame must not be in the same document as the frame'sdefinition.

ILLEGAL EXAMPLE:
The following frameset definition is not legal HTML since the contents of thesecond frame are in the same document as the frameset.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"   "http://www.w3.org/TR/html4/frameset.dtd"><HTML><HEAD><TITLE>A frameset document</TITLE></HEAD><FRAMESET cols="50%,50%">  <FRAME src="contents_of_frame1.html">  <FRAME src="#anchor_in_same_document">  <NOFRAMES>...some text...  <H2><A name="anchor_in_same_document">Important section</A></H2>...some text...  </NOFRAMES></FRAMESET></HTML>

Visual rendering of a frame 

The following example illustrates the usage of the decorativeFRAMEattributes. We specify that frame 1 will allow no scroll bars. Frame 2 willleave white space around its contents (initially, an image file) and the framewill not be resizeable. No border will be drawn between frames 3 and 4. Borderswill be drawn (by default) between frames 1, 2, and 3.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"   "http://www.w3.org/TR/html4/frameset.dtd"><HTML><HEAD><TITLE>A frameset document</TITLE></HEAD><FRAMESET cols="33%,33%,33%">  <FRAMESET rows="*,200">      <FRAME src="contents_of_frame1.html" scrolling="no">      <FRAME src="contents_of_frame2.gif"                 marginwidth="10" marginheight="15"                noresize>  </FRAMESET>  <FRAME src="contents_of_frame3.html" frameborder="0">  <FRAME src="contents_of_frame4.html" frameborder="0"></FRAMESET></HTML>

16.3Specifyingtarget frame information

Note. For information about current practice indetermining the target of a frame, please consult thenotes on frames in theappendix.

Attribute definitions

target =frame-target[CI]
This attribute specifies the name of a frame where a document is to beopened.
By assigning a name to a frame via thename attribute, authors canrefer to it as the "target" of links defined by other elements. Thetargetattribute may be set for elements that create links (A,LINK), image maps (AREA), and forms (FORM).

Please consult the section ontarget frame names for information about recognized frame names.

This example illustrates how targets allow the dynamic modification of aframe's contents. First we define a frameset in the documentframeset.html, shown here:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"   "http://www.w3.org/TR/html4/frameset.dtd"><HTML><HEAD><TITLE>A frameset document</TITLE></HEAD><FRAMESET rows="50%,50%">   <FRAME name="fixed" src="init_fixed.html">   <FRAME name="dynamic" src="init_dynamic.html"></FRAMESET></HTML>

Then, ininit_dynamic.html, we link to the frame named"dynamic".

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   "http://www.w3.org/TR/html4/loose.dtd"><HTML><HEAD><TITLE>A document with anchors with specific targets</TITLE></HEAD><BODY>...beginning of the document...<P>Now you may advance to     <A href="slide2.html">slide 2.</A>...more document...<P>You're doing great. Now on to    <A href="slide3.html">slide 3.</A></BODY></HTML>

Activating either link opens a new document in the frame named "dynamic"while the other frame, "fixed", maintains its initial contents.

Note. A frameset definition never changes,but the contents of one of its frames can. Once the initial contents of a framechange, the frameset definition no longer reflects the current state of itsframes.

There is currently no way to encode the entire state of a frameset in aURI. Therefore, many user agents do not allow users to assign a bookmark to aframeset.

Framesets may make navigation forward and backward throughyour user agent's history more difficult for users.

16.3.1Setting the default target for links

When many links in the same document designate the same target, it ispossible to specify the target once and dispense with thetargetattribute of each element. This is done by setting thetargetattribute of theBASE element.

We return to the previous example, this time factoring the targetinformation by defining it in theBASE element and removing it fromtheA elements.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   "http://www.w3.org/TR/html4/loose.dtd"><HTML><HEAD><TITLE>A document with BASE with a specific target</TITLE><BASE href="http://www.mycom.com/Slides"></HEAD><BODY>...beginning of the document...<P>Now you may advance to <A href="slide2.html">slide 2.</A>...more document...<P>You're doing great. Now on to        <A href="slide3.html">slide 3.</A></BODY></HTML>

16.3.2Target semantics

User agents should determine the target frame in which to load a linkedresource according to the following precedences (highest priority tolowest):

  1. If an element has itstarget attribute set to a known frame, when theelement is activated (i.e., a link is followed or a form is processed), theresource designated by the element should be loaded into the target frame.
  2. If an element does not have thetarget attribute set but theBASE element does, theBASE element'stargetattribute determines the frame.
  3. If neither the element nor theBASE element refers to a target,the resource designated by the element should be loaded into the framecontaining the element.
  4. If anytarget attribute refers to an unknown frameF, theuser agent should create a new window and frame, assign the nameF tothe frame, and load the resource designated by the element in the newframe.

User agents may provide users with a mechanism to override thetargetattribute.

16.4Alternate content

Authors should supply alternate content for those user agents that do notsupport frames or are configured not to display frames.

16.4.1 TheNOFRAMES element

<![%HTML.Frameset; [<!ENTITY % noframes.content "(BODY) -(NOFRAMES)">]]><!ENTITY % noframes.content "(%flow;)*"><!ELEMENTNOFRAMES - -%noframes.content; -- alternate content container for non frame-based rendering --><!ATTLIST NOFRAMES%attrs;                              --%coreattrs,%i18n,%events --  >

Attributes defined elsewhere

TheNOFRAMES element specifies content that should be displayed only byuser agents that do not support frames or are configured not to display frames.User agents that support frames must only display the contents of aNOFRAMES declaration when configured not to display frames. Useragents that do not support frames must display the contents ofNOFRAMES in any case.

TheNOFRAMES element is part of both thetransitional and frameset DTDs. In adocument that uses the frameset DTD,NOFRAMESmay beused at the end of the FRAMESET section of the document.

For example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"     "http://www.w3.org/TR/html4/frameset.dtd">  <HTML>  <HEAD>  <TITLE>A frameset document with NOFRAMES</TITLE>  </HEAD>  <FRAMESET cols="50%, 50%">     <FRAME src="main.html">     <FRAME src="table_of_contents.html">     <NOFRAMES>     <P>Here is the <A href="main-noframes.html">              non-frame based version of the document.</A>      </NOFRAMES>  </FRAMESET>  </HTML>

NOFRAMES may be used, for example, in a document that is the sourceof a frame and that uses the transitional DTD. This allows authors to explainthe document's purpose in cases when it is viewed out of the frameset or with auser agent that doesn't support frames.

16.4.2Longdescriptions of frames

Thelongdesc attribute allows authors to make framedocuments more accessible to people using non-visual user agents. Thisattribute designates a resource that provides a long description of the frame.Authors should note that long descriptions associated with frames are attachedto theframe, not the frame's contents. Since the contents may varyover time, the initial long description is likely to become inappropriate forthe frame's later contents. In particular, authors should not include an imageas the sole content of a frame.

The following frameset document describes two frames. The left framecontains a table of contents and the right frame initially contains an image ofan ostrich:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"   "http://www.w3.org/TR/html4/frameset.dtd"><HTML><HEAD><TITLE>A poorly-designed frameset document</TITLE></HEAD><FRAMESET cols="20%, 80%">   <FRAME src="table_of_contents.html">   <FRAME src="ostrich.gif" longdesc="ostrich-desc.html"></FRAMESET></HTML>

Note that the image has been included in the frame independently of any HTMLelement, so the author has no means of specifying alternate text other than viathelongdesc attribute. If the contents of the right framechange (e.g., the user selects a rattlesnake from the table of contents), userswill have no textual access to the frame's new content.

Thus, authors should not put an image directly in a frame. Instead, theimage should be specified in a separate HTML document, and therein annotatedwith the appropriate alternate text:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"   "http://www.w3.org/TR/html4/frameset.dtd"><HTML><HEAD><TITLE>A well-designed frameset document</TITLE></HEAD><FRAMESET cols="20%, 80%">   <FRAME src="table_of_contents.html">   <FRAME src="ostrich-container.html"></FRAMESET></HTML>
<!-- In ostrich-container.html: --><HTML><HEAD><TITLE>The fast and powerful ostrich</TITLE></HEAD><P><OBJECT data="ostrich.gif" type="image/gif">These ostriches sure taste good!</OBJECT></HTML>

16.5Inlineframes: theIFRAME element

<!ELEMENTIFRAME - - (%flow;)*         -- inline subwindow --><!ATTLIST IFRAME%coreattrs;                          --id,class,style,title --longdesc%URI;          #IMPLIED  -- link to long description                                          (complements title) --nameCDATA          #IMPLIED  -- name of frame for targetting --src%URI;          #IMPLIED  -- source of frame content --frameborder (1|0)          1         -- request frame borders? --marginwidth%Pixels;       #IMPLIED  -- margin widths in pixels --marginheight%Pixels;      #IMPLIED  -- margin height in pixels --scrolling   (yes|no|auto)  auto      -- scrollbar or none --align%IAlign;       #IMPLIED  -- vertical or horizontal alignment --height%Length;       #IMPLIED  -- frame height --width%Length;       #IMPLIED  -- frame width --  >

Attribute definitions

longdesc =uri[CT]
This attribute specifies a link to a long description of the frame. Thisdescription should supplement the short description provided using thetitle attribute, and is particularly useful for non-visual useragents.
name =cdata[CI]
This attribute assigns a name to the current frame. This name may be usedas the target of subsequent links.
width =length[CN]
The width of the inline frame.
height =length[CN]
The height of the inline frame.

Attributes defined elsewhere

TheIFRAME element allows authors to insert a frame within a block oftext. Inserting an inline frame within a section of text is much like insertingan object via theOBJECT element: they both allow you to insert anHTML document in the middle of another, they may both be aligned withsurrounding text, etc.

The information to be inserted inline is designated by thesrc attribute of this element. Thecontents of theIFRAMEelement, on the other hand, should only be displayed by user agents that do notsupport frames or are configured not to display frames.

For user agents that support frames, the following example will place aninline frame surrounded by a border in the middle of the text.

  <IFRAME src="foo.html" width="400" height="500"             scrolling="auto" frameborder="1">  [Your user agent does not support frames or is currently configured  not to display frames. However, you may visit  <A href="foo.html">the related document.</A>]  </IFRAME>

Inline frames may not be resized (and thus, they do not take thenoresize attribute).

Note. HTML documents may also be embedded in other HTMLdocuments with theOBJECT element. See the section onembedded documents fordetails.


previous  next  contents  elements  attributes  index

[8]ページ先頭

©2009-2025 Movatter.jp