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)
现在假设top.html (即上面的页面) 有七个button来实现对bottom.html (即下面的页面) 的刷新,可以用以下七种语句,哪个好用自己看着办了。
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
内框架对外框架刷新:
frame.html 由上(top.html)下(bottom.html)两个页面组成,代码如下:
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2
<HTML>
3
<HEAD>
4
<TITLE> frame </TITLE>
5
</HEAD>
6
<frameset rows="50%,50%">
7
<frame name=top src="top.html">
8
<frame name=bottom src="bottom.html">
9
</frameset>
10
</HTML>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 2
<HTML> 3
<HEAD> 4
<TITLE> frame </TITLE> 5
</HEAD> 6
<frameset rows="50%,50%"> 7
<frame name=top src="top.html"> 8
<frame name=bottom src="bottom.html"> 9
</frameset> 10
</HTML>
现在假设top.html (即上面的页面) 有七个button来实现对bottom.html (即下面的页面) 的刷新,可以用以下七种语句,哪个好用自己看着办了。
1
top.html 页面的代码如下:
2
3
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
4
<HTML>
5
<HEAD>
6
<TITLE> top.html </TITLE>
7
</HEAD>
8
<BODY>
9
<input type=button value="刷新1" onclick="window.parent.frames[1].location.reload()"><br>
10
<input type=button value="刷新2" onclick="window.parent.frames.bottom.location.reload()"><br>
11
<input type=button value="刷新3" onclick="window.parent.frames['bottom'].location.reload()"><br>
12
<input type=button value="刷新4" onclick="window.parent.frames.item(1).location.reload()"><br>
13
<input type=button value="刷新5" onclick="window.parent.frames.item('bottom').location.reload()"><br>
14
<input type=button value="刷新6" onclick="window.parent.bottom.location.reload()"><br>
15
<input type=button value="刷新7" onclick="window.parent['bottom'].location.reload()"><br>
16
</BODY>
17
</HTML>
18
top.html 页面的代码如下: 2

3
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 4
<HTML> 5
<HEAD> 6
<TITLE> top.html </TITLE> 7
</HEAD> 8
<BODY> 9
<input type=button value="刷新1" onclick="window.parent.frames[1].location.reload()"><br> 10
<input type=button value="刷新2" onclick="window.parent.frames.bottom.location.reload()"><br> 11
<input type=button value="刷新3" onclick="window.parent.frames['bottom'].location.reload()"><br> 12
<input type=button value="刷新4" onclick="window.parent.frames.item(1).location.reload()"><br> 13
<input type=button value="刷新5" onclick="window.parent.frames.item('bottom').location.reload()"><br> 14
<input type=button value="刷新6" onclick="window.parent.bottom.location.reload()"><br> 15
<input type=button value="刷新7" onclick="window.parent['bottom'].location.reload()"><br> 16
</BODY> 17
</HTML> 18

本文介绍JavaScript中用于刷新页面的八种方法,包括使用history、location等API的不同方式,并提供了内框架对外框架进行刷新的具体实现案例。

6196

被折叠的 条评论
为什么被折叠?



