您现在的位置: 网页制作教程网 >> 网页特效 >> Javascript 教程 >> 文章正文

Javascript 刷新框架及页面的方法总集

作者:aspcool

来源:aspcool

热度:

2007-10-31 12:42:30

声明:
   最近越来越感觉JS的优越性,项目中用到关于框架页面刷新的方法,在网上搜索以后发现有许多不错的代码,但不是很齐全。于是,我索性从网络上搜集以后经过精心编排,整理了一下。^ - ^ 希望大家多多指教!
  
  先来看一个简单的例子:
  下面以三个页面分别命名为frame.html、top.html、bottom.html为例来具体说明如何做。
  
  frame.html 由上(top.html)下(bottom.html)两个页面组成,代码如下:
  <!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>
  
  现在假设top.html (即上面的页面) 有七个button来实现对bottom.html (即下面的页面) 的刷新,可以用以下七种语句,哪个好用自己看着办了。
  
  语句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();
  
  top.html 页面的代码如下:
  
  
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  <HTML>
   <HEAD>
   <TITLE> top.html </TITLE>
   </HEAD>
  <BODY>
  <input type=button value="刷新1" onclick="window.parent.frames[1].location.reload()"><br>
  <input type=button value="刷新2" onclick="window.parent.frames.bottom.location.reload()"><br>
  <input type=button value="刷新3" onclick="window.parent.frames['bottom'].location.reload()"><br>
  <input type=button value="刷新4" onclick="window.parent.frames.item(1).location.reload()"><br>
  <input type=button value="刷新5" onclick="window.parent.frames.item('bottom').location.reload()"><br>
  <input type=button value="刷新6" onclick="window.parent.bottom.location.reload()"><br>
  <input type=button value="刷新7" onclick="window.parent['bottom'].location.reload()"><br>
  </BODY>
  </HTML>
  下面是bottom.html页面源代码,为了证明下方页面的确被刷新了,在装载完页面弹出一个对话框。
  
  bottom.html 页面的代码如下:
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  <HTML>
   <HEAD>
   <TITLE> bottom.html </TITLE>
   </HEAD>
  <BODY onload="alert('我被加载了!')">
  <h1>This is the content in bottom.html.</h1>
  </BODY>
  </HTML> 
   
  

[1] [2] 下一页


我来说两句:

1分 2分 3分 4分 5分
姓名: *


* 请各位网友遵纪守法并注意语言文明。
网站简介 | 联系方式 | 意见建议 | 版权说明
Copyright © 2007 All rights reserved
滇ICP备06006992号