JavaScript DOM Frame Object

1. Frame Object

  • Frame object represents an HTML frame which defines one particular window(frame) within a frameset.
  • It defines the set of frame that make up the browser window.
  • It is a property of the window object.

  • Syntax:<frame>

  • It has no end tag but they need to be closed properly.
  • It is an HTML element.
  • It defines a particular area in which another HTML document can be displayed.
  • A frame should be used within a <FRAMESET> tag.
<FRAME> Tag Attributes

AttributeDescription
srcIt is used to give the file name that should be located in the frame. Its value can be any URL.
For example: src= “/html/abc.html”
nameIt allows you to give a name to a frame. This attribute is used to indicate that a document should be loaded into a frame.
frameborderIt specifies whether or not the borders of that frame are shown. This attribute overrides the value given in the frameborder attribute on the tag if one is given. This can take values either 1 (Yes) or 0 (No).
marginwidthIt allows you to specify the width of the space between the left and right of the frame's border and the content. The value is given in pixels.
For example: marginwidth = “10”.
marginheightIt allows you to specify the height of the space between the top and bottom of the frame's borders and its contents. The value is given in pixels.
For example: marginheight = “10”.
noresizeBy default, you can resize any frame by clicking and dragging on the borders of a frame. It prevents a user from being able to resize the frame.
For example: noresize = “noresize”.
scrollingIt controls the appearance of the scrollbars that appear on the frame. It takes values either “Yes”, “No” or “Auto”.
For example: scrolling = “no” means it should not have scroll bars.
longdescIt allows you to provide a link to another page which contains a long description of the contents of the frame.
For example: longdesc = “framedescription.html”

2. Frameset Object

  • Frameset object holds two or more frame elements and each frame element in turn holds a separate document.
  • This object states only how many columns or rows there will be in the frameset.
Syntax:
<frameset> . . . </frameset>

<FRAMESET> Tag Attributes

AttributeDescription
cols (Columns)It specifies how many columns are to be contained in the frameset and the size of each column.
rowsIt works like the 'cols' attribute and takes the same values, but it is used to specify the number of rows in the frameset.
borderIt specifies the width of the border of each frame in pixels. For example; border = “5”. A value of zero means no border.
frameIt specifies whether a three-dimensional border should be displayed between frames. It takes value either 1 (Yes) or 0 (No).
For example: frameborder = “0” specifies no border.
framespacingIt specifies the amount of space between frames in a frameset. It can take any integer value.
For example: framespacing = “10” means there should be 10 pixels spacing between each frame.

Example : Frameset Tag

<frameset cols="50%,50%">
     <frame src="<frame src="http://www.tutorialride.com" />
     <frame src="http://www.tutorialride.com/javascript/javascript-dom-frame-object.htm" />
</frameset>


Output:

frameset output

3. IFrame Object

IFrame object represents an HTML inline frame that contains another document.

Frame Object Properties

PropertyDescription
AlignIt aligns the iframe.
contentDocumentIt returns the document object generated by a frame/iframe.
contentWindowIt returns the window object generated by a frame/iframe.
frameBorderIt sets frame border in a frame/iframe.
HeightIt sets the height in an iframe.
longDescIt sets the value of the longdesc attribute in a frame/iframe.
marginHeightIt sets the margin height in a frame/iframe.
marginWidthIt sets the margin width in a frame/iframe.
NameIt specifies the name to the frame.
noResizeIt disables the frame resizing capability.
scrollingIt controls the appearance of horizontal and vertical scrollbars in a frame.
SrcIt indicates the location of the web page to be loaded into the frame.
WidthIt sets or returns the value of the width attribute in an iframe.

4. Link Object

  • Link object represents an HTML link element.
  • It is used to link to external stylesheets.
  • It must be placed inside the head section of an HTML document.
  • It specifies a link to an external resources.
Link Object Properties

PropertyDescription
hrefIt sets the URL of a linked document.
hostIt sets the URL host name and port.
hostnameIt sets the URL hostname.
pathnameIt sets the URL pathname.
PortIt sets the URL port section.
ProtocolIt sets the URL protocol section including the colon (:) after protocol name.
SearchIt sets the URL query string section that is after including the questions mark (?).
TargetIt sets the URL link's target name.