iframe的用法(转帖2篇)

(转自:http://www.webshu.com/tutorial/tor/7,id=0408.htm

iframe嵌入网页的用法作者:自由勇点击:MT-8000最后更新 2003-10-12

iframe并不是很常用的,在标准的网页中非常少用。但是有朋友经常问到,下面我简单地介绍一下它的用法,你只要熟练掌握这些参数足矣。

<iframe>也应该是框架的一种形式,它与<frame>不同的是,iframe可以嵌在网页中的任意部分。我们举第一个例子,具体代码如:

<iframe width=420 height=330 frameborder=0 scrolling=auto src=URL></iframe>,这里的URL可以是相对路径,也可以是绝对路径,效果如:

width表示宽度,height表示宽度,可根据实际情况调整。

scrolling表示是否显示页面滚动条,可选的参数为auto、yes、no,如果省略这个参数,则默认为auto。

二、如何实现页面上的超链接指向这个嵌入的网页?

只要给这个iframe命名就可以了。方法是<iframe name=**>,例如我命名为aa,写入这句HTML语言<iframe width=420 height=330 name=aa frameborder=0 src=http://www.cctv.com></iframe>,然后,网页上的超链接语句应该写为:<a href=URL target=aa>

效果如下,请点击这里:中央电视台

三、如果把frameborder设为1,效果就像文本框一样,如下:

网页树树版权声明:

此文为Webshu.com独家撰稿,著作权属作者所有。

传统媒体、公众站点转载请事先联系Webshu编辑。

此文网址 http://www.webshu.com/tutorial/tor/7,id=0408.htm

(转自:http://www.htmlhelp.com/reference/html40/special/iframe.html

The Web Design Group

IFRAME - Inline Frame

Syntax <IFRAME>...</IFRAME>

Attribute Specifications

    * SRC=URI (URI of frame content)

    * NAME=CDATA (name of frame)

    * LONGDESC=URI (link to long description)

    * WIDTH=Length (frame width)

    * HEIGHT=Length (frame height)

    * ALIGN=[ top | middle | bottom | left | right ] (frame alignment)

    * FRAMEBORDER=[ 1 | 0 ] (frame border)

    * MARGINWIDTH=Pixels (margin width)

    * MARGINHEIGHT=Pixels (margin height)

    * SCROLLING=[ yes | no | auto ] (ability to scroll)

    * core attributes

Contents Inline elements, block-level elements

Contained in Block-level elements, inline elements except BUTTON

The IFRAME element defines an inline frame for the inclusion of external objects including other HTML documents. IFRAME provides a subset of the functionality of OBJECT; the only advantage to IFRAME is that an inline frame can act as a target for other links. OBJECT is more widely supported than IFRAME, and, unlike IFRAME, OBJECT is included in HTML 4.0 Strict.

IFRAME's SRC attribute provides the location of the frame content--typically an HTML document. The optional NAME attribute specifies the name of the inline frame, allowing links to target the frame.

The content of the IFRAME element is used as an alternative for browsers that are not configured to show or do not support inline frames. The content may consist of inline or block-level elements, though any block-level elements must be allowed inside the containing element of IFRAME. For example, an IFRAME within an H1 cannot contain an H2, but an IFRAME within a DIV can contain any block-level elements.

The LONGDESC attribute gives the URI of a long description of the frame's contents. This is particularly useful for full descriptions of embedded objects. Note that LONGDESC describes the frame content while the content of the IFRAME element acts as a replacement when the external resource cannot be inlined.

An example follows:

<IFRAME SRC="recipe.html" TITLE="The Famous Recipe">

<!-- Alternate content for non-supporting browsers -->

<H2>The Famous Recipe</H2>

<H3>Ingredients</H3>

...

</IFRAME>

The WIDTH and HEIGHT attributes specify the dimensions of the inline frame in pixels or as a percentage of the available space. The FRAMEBORDER attribute specifies whether or not a border should be drawn. The default value of 1 results in a border while a value of 0 suppresses the border. Style sheets allow greater flexibility in suggesting the border presentation.

The ALIGN attribute specifies the alignment of the inline frame. The values top, middle, and bottom specify the frame's position with respect to surrounding content on its left and right.

ALIGN=middle aligns the center of the frame with the current baseline. To center the frame horizontally on the page, place the frame in a centered block, e.g.,

<P ALIGN=center><IFRAME SRC="foo.html" WIDTH=300 HEIGHT=100></IFRAME></P>

The other ALIGN values, left and right, specify a floating frame; the frame is placed at the left or right margin and content flows around it. To place content below the frame, use <BR CLEAR=left|right|all> as appropriate.

The vertical-align and float properties of Cascading Style Sheets provide more flexible methods of aligning inline frames.

The MARGINWIDTH and MARGINHEIGHT attributes define the number of pixels to use as the left/right margins and top/bottom margins, respectively, within the inline frame. The value must be greater than one pixel.

The SCROLLING attribute specifies whether scrollbars are provided for the inline frame. The default value, auto, generates scrollbars only when necessary. The value yes gives scrollbars at all times, and the value no suppresses scrollbars--even when they are needed to see all the content. The value no should never be used.

More Information

    * IFRAME in W3C HTML 4.0 Recommendation

    * Using inline frames

Maintained by Liam Quinn <liam@htmlhelp.com>

Web Design Group ~ HTML 4.0 Reference ~ Elements by Function ~ Elements Alphabetically

Copyright © 1998-2000 Liam Quinn. All rights reserved.