风景旧曾谙,阳春三月归;烟云十年后,又见江南花。夜晚的这一刻,我独赏风景。有很多人觉得,一个人旅行好无聊。可我却偏偏喜欢一个人。
时间太晚了,就水一篇简单点的博文吧。写一写利用 js 脚本来刷新页面的几种常用方法!
js reload() 方法来刷新网页
reload():方法用于重新加载当前文档。
语法:
location.reload(force);
参数:
force:可选参数, 默认为 false,从客户端缓存里取当前页。如设置为 true 则从服务器拉取页面,相当于 F5 刷新!
注意:
在页面含有 post 提交的 from 表单时,如果使用 location.reload() 来刷新页面,当能会造成重复提交或一些其它的状态,个人使用时要注意!
例:
<html>
<head>
</head>
<body>
<input type="button" value="点击我刷新页面" onclick="reloadPage()" />
<p></p>
<script type="text/javascript">
function reloadPage() {
window.location.reload()
}
</script>
</body>
</html>js replace() 方法来刷新网页
replace():可通过指定的URL来替换当前的页面,需要注意的是,使用此方法之后,浏览器的“前进”和“后退”可能会失效!
语法:
location.replace(URL)
注意:
replace() 方法刷新页面时,会从服务器重新拉取页面,可以在一些含有 from 表单的页面中使用!
例1:js 刷新成别一个页面:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<input type="button" value="点击访问我的博客" onclick="replaceDoc()">
<p></p>
<script>
function replaceDoc() {
window.location.replace("http://www.feiniaomy.com")
}
</script>
</body>
</html>例2:js 刷新当前页面
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<input type="button" value="点击刷新页面" onclick="replaceDoc()">
<p></p>
<script>
function replaceDoc() {
location.replace(location.href);
}
</script>
</body>
</html>js 刷新页面的其它方法
<script>
history.go(0) //刷新当前页
history.go(1) //返回上一页
location.reload()
location = location
location.assign(location)
document.execCommand('Refresh')
window.navigate(location)
location.replace(location)
document.URL = location.href
</script>Js 刷新框架页的代码
<script>
window.parent.frames[1].location.reload();
window.parent.frames.bottom.location.reload();
window.parent.frames["bottom"].location.reload();
window.parent.frames.item(1).location.reload();
window.parent.frames.item('bottom').location.reload();
window.parent.bottom.location.reload();
window.parent['bottom'].location.reload();
</script>页面开窗口或关闭时自动刷新
<body onload="opener.location.reload()"> 开窗时刷新 <body onUnload="opener.location.reload()"> 关闭时刷新 <script language="javascript"> window.opener.document.location.reload() </script>
本文javascript 刷新当前页面的好代码教程到此结束。你不能决定生命的长短,但你可以控制它的质量。小编再次感谢大家对我们的支持!