How to create HTML frames – Frames part 5

How to create HTML frames – Frames part 5 cover image
  1. Home
  2. HTML
  3. How to create HTML frames – Frames part 5

The NAME attribute

The name attribute of the <FRAME> tag helps us gives names to our frames so that they can be referenced. This is especially useful for client-side scripting using JavaScript or VBScript.

To see what NAME can do for us, we shall build upon our previous examples by introducing hyperlinks and loading contents using them.

Firstly, we shall make another file frames4.html. Check out its code:

<HTML>
<HEAD><TITLE>Intelligent Frames</TITLE>
</HEAD>
<FRAMESET COLS="20%, 80%">

   <FRAME SRC="menu2.html" NAME="menuframe">
   <FRAME SRC="home.html" NAME="mainframe">

</FRAMESET>
<NOFRAMES>
There is no frame support on your browser.
</NOFRAMES>
</HTML>

Note: We load menu2.html in menuframe and home.html in mainframe.

Secondly, we modify the navigational menu frame by adding hyperlinks.

<HTML>
<HEAD><TITLE>Menu</TITLE>
</HEAD>
<BODY BGCOLOR="#FFCCFF">

<A HREF="home.html" TARGET="mainframe">Homepage</A>
<BR>
<A HREF="lions.html" TARGET="mainframe">Lions</A>
<BR>
<A HREF="tigers.html" TARGET="mainframe">Tigers</A>
<BR>
<A HREF="bears.html" TARGET="mainframe">Bears</A>
<BR>

</BODY>
</HTML>

Note the TARGET attribute in anchor tag that specifies the mainframe, the name of our right frame.

Thus, when a link is clicked on the navigational frame, the contents of the linked document will be displayed in mainframe. If we skip to add this attribute, the contents will be loaded in the same frame that carries the link.

Play with the file and understand how this works. Click here.

HTML