一、先來看一個簡單的例子:
下面以三個頁面分別命名為frame.html、top.html、bottom.html為例來具體說明如何做。
frame.html 由上(top.html)下(bottom.html)兩個頁面組成,代碼如下:
復(fù)制代碼 代碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> frame </TITLE>
</HEAD>
<frameset rows="50%,50%">
<frame name=top src="top.html">
<frame name=bottom src="bottom.html">
</frameset>
</HTML>
復(fù)制代碼 代碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> top.html </TITLE>
</HEAD>
<BODY>
<input type=button value="刷新1"><br>
<input type=button value="刷新2"><br>
<input type=button value="刷新3"><br>
<input type=button value="刷新4"><br>
<input type=button value="刷新5"><br>
<input type=button value="刷新6"><br>
<input type=button value="刷新7"><br>
</BODY>
</HTML>
復(fù)制代碼 代碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> bottom.html </TITLE>
</HEAD>
<BODY>
<h1>This is the content in bottom.html.</h1>
</BODY>
</HTML>
復(fù)制代碼 代碼如下:
1.window指代的是當(dāng)前頁面,例如對于此例它指的是top.html頁面。
2.parent指的是當(dāng)前頁面的父頁面,也就是包含它的框架頁面。例如對于此例它指的是framedemo.html。
3.frames是window對象,是一個數(shù)組。代表著該框架內(nèi)所有子頁面。
4.item是方法。返回?cái)?shù)組里面的元素。
5.如果子頁面也是個框架頁面,里面還是其它的子頁面,那么上面的有些方法可能不行。
附:
Javascript刷新頁面的幾種方法:
1 history.go(0)
2 location.reload()
3 location=location
4 location.assign(location)
5 document.execCommand('Refresh')
6 window.navigate(location)
7 location.replace(location)
8 document.URL=location.href
[Ctrl+A 全選 注:如需引入外部Js需刷新才能執(zhí)行]
復(fù)制代碼 代碼如下:
1 PrintWriter out = response.getWriter();
2 out.write("<script type=/"text/javascript/">");
3 ////子窗口刷新父窗口
4 out.write("self.opener.location.reload();");
5 //關(guān)閉窗口
6 out.write("window.opener=null;");
7 out.write("window.close();");
8 out.write("</script>");
復(fù)制代碼 代碼如下:
<script language=JavaScript>
parent.location.reload();
</script>
復(fù)制代碼 代碼如下:
<script language=JavaScript>
self.opener.location.reload();
</script>
復(fù)制代碼 代碼如下:
語句1. window.parent.frames[1].location.reload();
語句2. window.parent.frames.bottom.location.reload();
語句3. window.parent.frames["bottom"].location.reload();
語句4. window.parent.frames.item(1).location.reload();
語句5. window.parent.frames.item('bottom').location.reload();
語句6. window.parent.bottom.location.reload();
語句7. window.parent['bottom'].location.reload();
復(fù)制代碼 代碼如下:
<script language="javascript">
window.opener.document.location.reload()
</script>
新聞熱點(diǎn)
疑難解答
圖片精選