js跳转页面方法汇总。

写在前面:主要内容如题,本文汇总了好几个网页的js跳转页面的方法,需要的朋友可以过来参考下,希望对大家有所帮助。

//js方式的页面跳转 

<!--脚本开始--> 
<script language="javascript" type=""> 
function countDown(secs){ 
tiao.innerText=secs; 
if(--secs>0) 
   setTimeout("countDown("+secs+")",1000); 
} 
countDown(3); 
</script> 
<!--脚本结束-->
//按钮式:(js点击跳转)
<INPUT name="pclog" type="button" value="GO" onClick="location.href='http://www.jb51.net/'">
//链接式:(css内联,点击跳转)
<a href="javascript:history.go(-1)">返回上一步</a>
<a href="<%=Request.ServerVariables("HTTP_REFERER")%>">返回上一步</a>
//直接跳转式:(location 属性是兼容所有浏览器的。因此在实现页面跳转的时候还是使用这个比较靠谱,在本窗口跳转,覆盖原有内容)
<script>window.location.href='http://www.jb51.net';</script>
//开新窗口:(新建窗口跳转)
<a href="javascript:" onClick="window.open('http://www.jb51.net','','height=500,width=611,scrollbars=yes,status=yes')">OBKoro1</a>

//window.navigate方式跳转 (不推荐,这个方法是只针对IE的,不适用于火狐等其他浏览器)
   <script language="javascript"> 
    window.navigate("top.jsp"); 
  </script> 
//3.window.loction.replace方式实现页面跳转,注意跟第一种方式的区别 
<script language="javascript"> 
    window.location.replace("#"); 
</script> 

//区别在于:wondow.history.back();方法是根据服务器记录的请求决定该跳到哪个页面的,所以会跳到系统默认页面1.jsp 。window.location.href("3.jsp");是向服务器发送请求的跳转,window.history.go(-1);wondow.history.back();方法是根据服务器记录的请求决定该跳到哪个页面的,所以就可以返回到2.jsp。

//4.self.location方式实现页面跳转,和下面的top.location有小小区别 
   <script language="JavaScript"> 
          self.location='top.htm'; 
   </script> 
//self.location区别:https://zhidao.baidu.com/question/45817801.html

//5.top.location 
   <script language="javascript"> 
          top.location='xx.jsp'; 
   </script>
`

自动刷新页面的方法:
1.页面自动刷新:把如下代码加入<head>区域中

<meta http-equiv="refresh" content="20">

其中20指每隔20秒刷新一次页面.

2.页面自动跳转:把如下代码加入<head>区域中

<meta http-equiv="refresh" content="20;url=http://www.wyxg.com">

其中20指隔20秒后跳转到页面

3.页面自动刷新js版

[c-sharp] view plain copy
<mce:script language="JavaScript"><!--
function myrefresh()
 {
 window.location.reload();
 }
 setTimeout('myrefresh()',1000); //指定1秒刷新一次
 // --></mce:script>

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

<body οnlοad="opener.location.reload()"> 开窗时刷新
<body onUnload="opener.location.reload()"> 关闭时刷新
<mce:script language="javascript"><!--
window.opener.document.location.reload()
 // --></mce:script>=====javascript中弹出选择框跳转到其他页面=====
<script language="javascript">
 <!-- function logout()...{ if (confirm("你确定要注销身份吗?是-选择确定,否-选择取消"))...{ window.location.href="logout.asp?act=logout" } } -->
 </script>=====javascript中弹出提示框跳转到其他页面=====
<script language="javascript">
 <!-- function logout()...{ alert("你确定要注销身份吗?"); window.location.href="logout.asp?act=logout" } -->