JS刷新框架中的其他页面 && JS刷新窗口方法汇总

JavaScript038

JS刷新框架中的其他页面 && JS刷新窗口方法汇总,第1张

先来看一个简单的例子 下面以三个页面分别命名为frame top bottom 为例来具体说明如何做 frame 由上(top )下(bottom )两个页面组成 代码如下

复制代码 代码如下: <! DOCTYPE HTML PUBLIC " //W C//DTD HTML Transitional//EN" ><HTML ><HEAD ><TITLE >frame </ TITLE ></ HEAD ><frameset rows =" % %" ><frame name =top   src ="top " ><frame name =bottom   src ="bottom " ></ frameset ></ HTML >

现在假设top (即上面的页面) 有七个button来实现对bottom (即下面的页面) 的刷新 可以用以下七种语句 哪个好用自己看着办了 语句 window parent frames[ ] location reload()语句 window parent frames bottom location reload() 语句 window parent frames["bottom"] location reload() 语句 window parent frames item( ) location reload()语句 window parent frames item( bottom ) location reload()语句 window parent bottom location reload()语句 window parent[ bottom ] location reload() top 页面的代码如下

复制代码 代码如下: <! DOCTYPE HTML PUBLIC " //W C//DTD HTML Transitional//EN" ><HTML ><HEAD >   <TITLE >top </ TITLE ></ HEAD ><BODY ><input type =button value ="刷新 " onclick ="window parent frames[ ] location reload()" ><br ><input type =button value ="刷新 " onclick ="window parent frames bottom location reload()" ><br ><input type =button value ="刷新 " onclick ="window parent frames[ bottom ] location reload()" ><br ><input type =button value ="刷新 " onclick ="window parent frames item( ) location reload()" ><br ><input type =button value ="刷新 " onclick ="window parent frames item( bottom ) location reload()" ><br ><input type =button value ="刷新 " onclick ="window parent bottom location reload()" ><br ><input type =button value ="刷新 " onclick ="window parent[ bottom ] location reload()" ><br ></ BODY ></ HTML >

下面是bottom 页面源代码 为了证明下方页面的确被刷新了 在装载完页面弹出一个对话框 bottom 页面的代码如下

复制代码 代码如下:  <! DOCTYPE HTML PUBLIC " //W C//DTD HTML Transitional//EN" ><HTML ><HEAD >   <TITLE >bottom </ TITLE ></ HEAD ><BODY onload ="alert( 我被加载了! )" ><h >This is the content in bottom </ h ></ BODY ></ HTML >lishixinzhi/Article/program/Java/JSP/201311/20510

js常见的几种页面刷新方法如下:

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

以上几种方法都是单纯的属性当前页面,如果框架页面中有子页面,只想刷新子页面的时候,可以用以下方法:

top.location.reload() 刷新整页

self.location.reload() 刷新本页

window.location.href="自定义页面地址"

自动刷新页面的方法:

在<head>标签中加入<meta http-equiv="refresh" content="10">

其中content是时间间隔,每10s刷新一次

在body中添加onload="opener.location.reload()",即<body onload="opener.location.reload()">为页面启动时刷新

在body中添加onUnload="opener.location.reload()",即<bodyonUnload="opener.location.reload()">为页面关闭时刷新