通過使用框架,可以在同一個瀏覽器窗口中顯示不止一個頁面。
- 框架結(jié)構(gòu)標(biāo)簽
<frameset>定義如何將窗口分割為框架 - 每個 frameset 定義了一系列行或列
- rows/columns 的值規(guī)定了每行或每列占據(jù)屏幕的面積
- 框架標(biāo)簽 Frame 標(biāo)簽定義了放置在每個框架中的 HTML 文檔
實(shí)例:
1、 <noframes> 標(biāo)簽
不能將 <body></body> 標(biāo)簽與 <frameset></frameset> 標(biāo)簽同時使用!不過,假如你添加包含一段文本的 <noframes> 標(biāo)簽,就必須將這段文字嵌套于 <body></body> 標(biāo)簽內(nèi)。
<html>
<frameset cols="25%,50%,25%">
<frame src="http://www.w3school.com.cn/example/html/frame_a.html"></frame>
<frame src="http://www.w3school.com.cn/example/html/frame_b.html"></frame>
<frame src="http://www.w3school.com.cn/example/html/frame_c.html"></frame>
<noframes>
<body>您的瀏覽器無法處理框架!</body>
</noframes>
</frameset>
</html>
2、混合框架結(jié)構(gòu)
<html>
<frameset rows="50%,50%">
<frame src="http://www.w3school.com.cn/example/html/frame_a.html"></frame>
<frameset cols="25%,75%">
<frame src="http://www.w3school.com.cn/example/html/frame_b.html"></frame>
<frame src="http://www.w3school.com.cn/example/html/frame_c.html"></frame>
</frameset>
</frameset>
</html>
3、含有 noresize="noresize"屬性的框架結(jié)構(gòu)
假如一個框架有可見邊框,用戶可以拖動邊框來改變它的大小。為了避免這種情況發(fā)生,可以在 <frame> 標(biāo)簽中加入:noresize="noresize"。
<html>
<frameset cols="25%,50%,25%">
<frame src="http://www.w3school.com.cn/example/html/frame_a.html" noresize="noresize"></frame>
<frame src="http://www.w3school.com.cn/example/html/frame_b.html"></frame>
<frame src="http://www.w3school.com.cn/example/html/frame_c.html"></frame>
</frameset>
</html>
4、導(dǎo)航框架
<html>
<frameset cols="120,*">
<frame src="http://www.w3school.com.cn/example/html/html_contents.html"></frame>
<frame src="http://www.w3school.com.cn/example/html/frame_a.html"></frame>
</frameset>
</html>
5、內(nèi)聯(lián)框架
<html>
<body>
<iframe src="http://www.w3school.com.cn/example/html/frame_a.html"></iframe>
<p>一些老的瀏覽器不支持 iframe。</p>
<p>如果得不到支持,iframe 是不可見的。</p>
</body>
</html>
6、跳轉(zhuǎn)至框架內(nèi)的一個指定的節(jié)
其中的一個框架設(shè)置了指向另一個文件內(nèi)指定的節(jié)的鏈接。這個"link.htm"文件內(nèi)指定的節(jié)使用 <a name="C10"> 進(jìn)行標(biāo)識。
<html>
<frameset cols="20%,80%">
<frame src="http://www.w3school.com.cn/example/html/frame_a.html"></frame>
<frame src="http://www.w3school.com.cn/example/html/link.html#C10"></frame>
</frameset>
</html>
7、內(nèi)聯(lián)框架
iframe 的語法
<iframe src="URL"></iframe>
iframe 設(shè)置高度和寬度
<html>
<body>
<iframe src="http://www.w3school.com.cn/example/html/demo_iframe.html" width="200" height="200"></iframe>
<p>某些老式的瀏覽器不支持內(nèi)聯(lián)框架。</p>
<p>如果不支持,則 iframe 是不可見的。</p>
</body>
</html>
iframe 刪除邊框
frameborder 屬性規(guī)定是否顯示 iframe 周圍的邊框。
設(shè)置屬性值為 "0" 就可以移除邊框:
<html>
<body>
<iframe src="http://www.w3school.com.cn/example/html/demo_iframe.html" width="200" height="200" frameborder="0"></iframe>
<p>某些老式的瀏覽器不支持內(nèi)聯(lián)框架。</p>
<p>如果不支持,則 iframe 是不可見的。</p>
</body>
</html>
使用 iframe 作為鏈接的目標(biāo)
iframe 可用作鏈接的目標(biāo)(target)。
鏈接的 target 屬性必須引用 iframe 的 name 屬性:
<html>
<body>
<iframe src="http://www.w3school.com.cn/example/html/demo_iframe.html" width="200" height="200" name="iframe_a"></iframe>
<p><a target="iframe_a">W3School.com.cn</a></p>
<p><b>注釋:</b>由于鏈接的目標(biāo)匹配 iframe 的名稱,所以鏈接會在 iframe 中打開。</p>
</body>
</html>