js页面刷新跳转的几种方式及区别

跳转常用方法:

window.location.href="index.php";  
window.history.back(-1);//类似于按钮,参数是负几,就后退几次。  
window.navigate("index.jsp"); //navigate对象包含有关浏览器的信息,也可以作为页面跳转,后面直接加要跳转的地方。  
  
self.location.href=index.htm;  
//self指代当前窗口对象,属于window最上层的对象;  
//location.href 指的是某window对象的URL地址.  
//self.location.href指当前窗口的URL地址,去掉self默认为当前窗口的URL地址.  
  
top.location=index.php;  
//top 属性返回最顶层的先辈窗口。  
//该属性返回队一个顶级窗口的只读引用。  
//如果窗口本身就是一个顶级窗口,top 属性存放对窗口自身的引用。  
//如果窗口是一个框架,那么 top 属性引用包含框架的顶层窗口。 

location.replace(document.referrer);  
document.referrer   
history.go(-1);//不刷新页面  
history.back();//不刷新页面  

 Javascript刷新页面的常用方法:

history.go(0)   
location.reload()   
location=location   
location.assign(location)   
document.execCommand('Refresh')   
window.navigate(location)   
location.replace(location)   
document.URL=location.href  

 自动刷新页面的方法:

1.页面自动刷新:把如下代码加入<head>区域中
<meta http-equiv="refresh" content="20">
其中20指每隔20秒刷新一次页面.

2.页面自动跳转:把如下代码加入<head>区域中
<meta http-equiv="refresh" content="20;url=http://www.baidu.com">
其中20指隔20秒后跳转到http://www.baidu.com页面

3.页面自动刷新js版
 //指定1秒刷新一次  
<script language="JavaScript">  
setTimeout('window.location.reload()',1000)
</script>  

 //如何刷新包含该框架的页面用   
<script language=JavaScript>  
   parent.location.reload();  
</script>  
 //子窗口刷新父窗口
<script language=JavaScript>  
    self.opener.location.reload();  
</script>  
( 或 <a href="javascript:opener.location.reload()">刷新</a>   )

 //如何刷新另一个框架的页面用   
    <script language=JavaScript>  
       parent.另一FrameID.location.reload();  
    </script>  
// 如果想关闭窗口时刷新或者想开窗时刷新的话,在<body>中调用以下语句即可。
<body onload="opener.location.reload()"> 开窗时刷新  
<body onUnload="opener.location.reload()"> 关闭时刷新  
<script language="javascript">  
window.opener.document.location.reload()  
</script>

 

posted @ 2018-01-22 11:51  lgp20151222  阅读(292)  评论(0编辑  收藏  举报