Language References
Defines the contents and appearance of an inline frame. | HTML 4, 5 |
HTML Syntax
<iframe
align = absbottom | absmiddle | baseline | bottom | left | middle | right | texttop | top
border = pixels
bordercolor = color
class = classname
datafld = colname
datasrc = #id
frameborder = no | yes | 0 | 1
framespacing = pixels
height = n
hspace = pixels
id = value
marginheight = pixels
marginwidth = pixels
name = window_name | _blank | _parent | _self | _top
noresize = noresize | resize
scrolling = auto | no | yes
src = url
style = css properties
title = text
vspace = pixels
width = n
>
The IFRAME element allows authors to insert a frame with its own contents within an HTML page. The IFRAME functions as a document within a document, or like a floating FRAME.
The IFRAME can display a distinct HTML document. The element’s src attribute specifies the initial document the IFRAME will contain. Authors can also provide alternate content, written between the IFRAME start and end tags, for browsers that do not support frames or are configured not to display frames.
The IFRAME is normally assigned a name to identify and reference the frame. This name may be used as the target of subsequent links.
Authors can also specify the appearance of an IFRAME, using the element’s rendering attributes. Unlike frames, an IFRAME can not be resized.
IFRAME Members
For browsers that support frames, the following example renders an inline frame containing the file sample.html.
<iframe src="sample.html" scrolling="auto" width="400" frameborder="1"></iframe>
The following provides alternate content which should be displayed only by browsers that do not support frames.
<iframe src="sample.html" ... >Your browser does not support frames or
is currently configured not to display frames. To view the related document,
click <a href="sample.html">here</a></iframe>
Properties of an IFRAME object can be accessed through the object model of the page where the IFRAME resides. Typical notation is:
IE4 and later
document.all['iframeID'].property
IE5 and NN6
document.getElementById ( 'iframeID' ).property
Assuming for example that we have an IFRAME object with an id=iframe1
. To access the border style of the IFRAME:
document.getElementById ( 'iframeID' ).style.border;
On the other hand, access to the objects of the source document of the IFRAME is provided through the frames collection. This allows authors to read or write to elements contained in the IFRAME. Typical notation is:
document.frames ( 'iframeID' ).document.object.property
For example, to access the backgroundColor of the BODY object in the IFRAME:
document.frames ( 'iframe1' ).document.body.style.backgroundColor = "khaki";
The following returns a collection of all elements of the document contained in the IFRAME, using the documentElement object.
var els = document.frames ( 'iframe1' ).document.documentElement.childNodes
FRAME frames Using Frames and Framesets