DIV CSS 佈局教程網

iframe 框架的應用範例與實作
編輯:Dreamweaver入門     

iframe 能在頁面中嵌入另一個網頁,是製作側邊欄、內容區等區塊時相當實用的元素。以下提供一份可直接套用的範例程式碼。

完整程式碼

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "https://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>iframe框架應用</title>
<style type="text/css">
body,td,th { font-size: 12px; }
body { margin: 0; }
a { font-size: 12px; }
</style>
</head>

<body>
<div class="title">
    <a href="/" target="iframea">標題文檔</a>
    <a href="b" target="iframea">標題文檔</a>
    <a href="c" target="iframea">標題文檔</a>
</div>
<iframe scrolling="no" name="iframea" height="300"></iframe>
</body>
</html>

原理說明

關鍵在於為 iframe 取一個名稱(這裡是 iframea),再讓上方各個連結的 target 指向這個名稱。如此一來,點擊不同的連結時,對應的頁面就會在下方這個固定高度為 300 的 iframe 區塊中載入顯示,而不會另開新視窗。你可以依需求調整 iframe 的 height、各連結的 href 與顯示文字。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved