References in frames

Because frames are a set of independent windows, in order for the link to open in the right place, you must specify the frame names.

Suppose we have a document consisting of two frames, named MENU and CONTENT, as shown in Fig. 1.

Fig. 1

Fig. 1. Document type with frames

Usually in the left frame there is a list of links to sections of the site, and in the right frame the contents of documents are displayed. To open a web page in a particular frame window, you should use the following code (example 1).

Example 1. Opening a document in a frame

Valid HTML
<! DOCTYPE HTML PUBLIC "- // W3C // DTD HTML 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text / html; charset = windows-1251">
<Title> Frames </ title>
</ Head>
<Body>

<P> <a href="http://www.shram.kiev.ua" target="CONTENT"> Link opens the site www.shram.kiev.ua in the frame named CONTENT </a> </ p>

</ Body>
</ Html>

If the target parameter "target =" CONTENT " is omitted, the document will open in the current frame where the link itself is located.

To simultaneously update two frames at the same time and load different documents into them, you'll have to use JavaScript (example 2).

Example 2. Simultaneous loading of documents into two frames

File index.html

Valid HTML
<! DOCTYPE HTML PUBLIC "- // W3C // DTD HTML 4.01 Frameset // EN" "http://www.w3.org/TR/html4/frameset.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text / html; charset = windows-1251">
<Title> File index.html </ title>
</ Head>
"<Frameset cols =" 200, * ">
<Frame src = "menu.html" name = "MENU" noresize>
<Frame src = "content.html" name = "CONTENT" >
</ Frameset>

File menu.html

Valid HTML
<! DOCTYPE HTML PUBLIC "- // W3C // DTD HTML 4.01 // EN" "http://www.w3.org/TR/html4/strict.dtd">
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text / html; charset = windows-1251">
<Title> File menu.html </ title>
</ Head>
<Body>
<P> <a href="menu2.html" onClick= "parent.frames['CONTENT'].document.location='content2.html'"> Click me, click </a> </ p>
</ Body>
</ Html>

The link is used as usual, but as an option, an onClick event is added that tracks the click on the link. Note that the name of the frame should also be written as specified in the parameter name (in this case, by uppercase characters). JavaScript is case sensitive and has a perverse attitude to any incorrect spelling.

Copyright © www.htmlbook.ru