[javascript学习指南]JavaScript刷新页面代码详解

更新时间:2018-02-14    来源:页面特效    手机版     字体:

【www.bbyears.com--页面特效】

先来给大家简单介绍一些刷新页面语句

 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 

定时页面自动刷新js版

程序代码

 代码如下


或这样写

 代码如下

<script language="Javascript">
function myrefresh()
{
       window.location.reload();
}
setTimeout("myrefresh()",1000); //指定1秒刷新一次
</script>


window.location.Reload()和window.location.href=window.location.href;

 代码如下


javascript:window.location.href=window.location.href;">

测试效果一样。表单没有提交。

 代码如下


都提交数据

 window.location.Reload()应该是刷新.(如果有数据提交的话,会提示是否提交的(是和否选项))
window.location.href=window.location.href; 是定向url提交数据

最好不要用location.reload(),而用location=location比较好,还有在模式窗口(showModalDialog和showModelessDialog)前者不能用。


js刷新窗口:window.location.replace(window.location.href)

 代码如下


window.location.reload();

window.history.go(0);

window.location.assign(window.location.href)

window.location.href和window.location.replace的区别:

1.html -> 2.html -> 3.html

系统从1.html到2.html后,2中有两个按钮,btn1是window.location.href=3.html, btn2是window.location.replace(3.html), 当点击btn1后在3中用window.history.go(-1);window.history.back();返回的是1.html,

而点击btn2进入3时,用window.history.go(-1);wondow.history.back();返回的是2.html

window.location.href和window.location.replace的亲身体验与区别

当用window.location.href是使用window.history.go(-1)或window.history.back()是管用的

当用window.location.replace("url")是使用window.history.go(-1)或window.history.back()是不管用的

window.location.replace("3.jsp");是不向服务器发送请求的跳转

window.history.go(-1);window.history.back();方法是根据服务器记录的请求决定该跳到哪个页面的

window.location.href("3.jsp");是向服务器发送请求的跳转,window.history.go(-1);wondow.history.back();方法是根据服务器记录的请求决定该跳到哪个页面的


JS刷新框架的脚本语句:

 代码如下

//如何刷新包含该框架的页面用
<script language=JavaScript>
parent.location.reload();
</script>
//子窗口刷新父窗口
<script language=JavaScript>
self.opener.location.reload();
</script>
(或刷新)
//如何刷新另一个框架的页面用
<script language=JavaScript>
parent.另一FrameID.location.reload();
</script>

如果想关闭窗口时刷新或者想开窗时刷新的话,在中调用以下语句即可:

 代码如下

开窗时刷新
关闭时刷新
<script language="javascript">
window.opener.document.location.reload()
</script>


刷新另一个框架的页面

语句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();

本文来源:http://www.bbyears.com/wangyetexiao/39249.html

热门标签

更多>>

本类排行