<HTML> <HEAD> <TITLE>My cool page, now with frames!</TITLE> </HEAD> <FRAMESET> cols="50%,50%"> <FRAME SRC="page1.htm"> <FRAME SRC="page2.htm"> </FRAMESET> </HTML>
瀏覽器依照由左向右的次序, 讀取 <FRAME> 標籤。假設網頁要三個框架垂直並排, 則只要再加上另一 <FRAME> 標籤, 如:
<FRAMESET cols="33%,33%,33%"> <FRAME SRC="page1.htm"> <FRAME SRC="page2.htm"> <FRAME SRC="page3.htm"> </FRAMESET>
假如網頁要由上而下安排框架, 則 <FRAMESET> 標籤中的 cols 參數改為 rows 就可以。
框架中可以再使用 <FRAMESET> 標籤安排另一框架組。 下例先將視窗分成上下兩個框架, 下面的框架再分成 左右兩個框架。
<FRAMESET rows="50%,50%">
<FRAME SRC="page1.htm">
<FRAMESET cols="50%,50%">
<FRAME SRC="page2.htm">
<FRAME SRC="page3.htm">
</FRAMESET>
</FRAMESET>
<HTML> <HEAD> <TITLE>My cool page, now with frames!</TITLE> </HEAD> <FRAMESET cols="60%,40%"> <FRAME SRC="page1.htm"> <FRAME SRC="page2.htm"> </FRAMESET> <noFRAMESET> Use the link below to go to the frameless version of the site.<BR> <A HREF="noframe.htm">Frameless Sites</A> </noFRAMESET> </HTML>
<HTML> <BODY> I am frame 1! </BODY> </HTML>
<HTML>
<BODY>
<SCRIPT language="JavaScript">
<!--
for (count=0; count<top.frames.length; count+=1)
{
var framenum=count+1;
document.write("Frame " + framenum + " is from "
+ top.frames[count].location);
document.write("<br>");
}
//-->
</SCRIPT>
</BODY>
</HTML>
例:
<FRAMESET cols="20%,80%">
<FRAME SRC="frame1.htm" name="left_frame">
<FRAME SRC="frame2.htm" name="right_frame">
</FRAMESET>
存取時即可使用框架名稱, 如
document.write(top.right_frame.location);
<A HREF="newpage.html" target="right_frame">New Page top.right_frame.location="newpage.html"; <A HREF="n" onClick="top.right_frame.location='newpage.html'; return false;">New Page</a> <A HREF="javascript:top.right_frame.location='newpage.html';">New Page</a>
<HTML> <HEAD> <TITLE>My cool page, now with frames!</TITLE> </HEAD> <FRAMESET cols="60%,40%"> <FRAME SRC="frame1.htm" name="left_frame"> <FRAME SRC="frame2.htm" name="right_frame"> </FRAMESET> <noFRAMESET> Use the link below to go to the frameless version of the site.<BR> <A HREF="noframe.htm">Frameless Sites</A> </noFRAMESET> </HTML>
<HTML>
<head>
<SCRIPT language="JavaScript">
<!--
function twoframes()
{
parent.right_frame.location="frame4.html";
self.location="frame3.html";
}
//-->
</SCRIPT>
</head>
<BODY>
<A HREF="javascript:twoframes();">Change Both Frames</A>
</BODY>
</HTML>
<HTML> <BODY> I am frame 2! </BODY> </HTML>例: frameset.html
<HTML> <FRAMESET cols="120,*"> <FRAME SRC="frame1.htm" name="top_frame"> <FRAME SRC="frame2.htm" name="bottom_frame"> </FRAMESET> <noFRAMESET> Use the link below to go to the frameless version of the site.<BR> <A HREF="noframe.htm">Frameless Sites</A> </noFRAMESET> </HTML>
<FORM name="f1">
Change the lower frame:
<select name="s1" onChange="top.bottom_frame.location=
document.f1.s1.options[document.f1.s1.selectedIndex].value;">
<option selected value="frame.htm">框架</option>
<option value="doc.htm">文件</option>
<option value="win.htm">視窗</option>
</select>
</FORM>
例: frameset.html
<HTML>
<head>
<SCRIPT language="JavaScript">
<!--
function check_frames()
{
if ( top.frames.length > 0 )
top.location="index.html";
}
//-->
</SCRIPT>
</head>
<BODY onLoad="check_frames();">
<H2>Welcome to my Page</H2>
</BODY>
</HTML>
<HTML>
<head>
<SCRIPT language="JavaScript">
<!--
function check_frames()
{
if ( top.frames.length == 0 )
top.location="index.html";
}
//-->
</SCRIPT>
</head>
<BODY onLoad="check_frames();">
<H2>Welcome to my Page</H2>
</BODY>
</HTML>
<HTML> <FRAMESET cols="150,*"> <FRAME SRC="frame1.html" name="left_frame"> <FRAME SRC="frame2.html" name="right_frame"> </FRAMESET> <noFRAMESET> Use the link below to go to the frameless version of the site.<BR> <A HREF="noframe.htm">Frameless Sites</A> </noFRAMESET> </HTML>
<HTML>
<head>
<SCRIPT language="JavaScript">
<!--
var thename="";
var thefood="";
//-->
</SCRIPT>
</head>
<BODY>
This is frame1.html, it holds the variable values. You can put any content you like here.
</BODY>
</HTML>
<HTML>
<head>
<SCRIPT language="JavaScript">
<!--
function store_info()
{
top.left_frame.thename=document.f1.yourname.value;
self.location="frame3.html";
}
//-->
</SCRIPT>
</head>
<BODY>
Please enter your name below.
<p>
<FORM name="f1">
Your name:
<input type="text" name="yourname" size="25">
<P>
<input type="button" value="Continue" onClick="store_info();">
</FORM>
</BODY>
</HTML>
<HTML>
<head>
<SCRIPT language="JavaScript">
<!--
function more_info()
{
top.left_frame.thefood=document.f2.yourfood.value;
self.location="frame4.html";
}
//-->
</SCRIPT>
</head>
<BODY
onLoad="document.f2.yourname.value=top.left_frame.thename;">
<SCRIPT language="JavaScript">
<!--
document.write("Hi, " + top.left_frame.thename + "!<br>");
//-->
</SCRIPT>
How I'd like to get your favorite food, please enter it below:
<p>
<FORM name="f2">
Your name:
<input type="text" name="yourname" size="25">
<P>
Favorite food:
<input type="text" name="yourfood" size="25">
<P>
<input type="button" value="Continue" onClick="more_info();">
</FORM>
</BODY>
</HTML>
<HTML>
<head>
<SCRIPT language="JavaScript">
<!--
function print_info()
{
document.write("Thank you, " + top.left_frame.thename + "!<p>");
document.write("You must really like " + top.left_frame.thefood + "!");
}
//-->
</SCRIPT>
</head>
<BODY>
<SCRIPT language="JavaScript">
<!--
print_info();
//-->
</SCRIPT>
</BODY>
</HTML>