JS 实现页面跳转的几种方法

我总结了这五种方法:

第一种:使用JS跳转页面

(1)跳转带参

<script language="javascript" type="text/javascript">
        window.location.href="jingxuan.do?backurl=" + window.location.href; 
 </script>

(2)跳转无参

<script>window.location.href='http://blog.yoodb.com';</script>

第二种:返回上一次预览界面

<script language="javascript">
   alert("返回");
   window.history.back(-1);
 </script>

HTML页面嵌套

<a href="javascript:history.go(-1)">返回上一步</a>
 <a href="<%=Request.ServerVariables("HTTP_REFERER")%>">返回上一步</a>

第三种:button按钮添加事件跳转

<input name="前端知音" type="button" value="前端知音" onClick="location.href='login.do'">

 第四种:在新窗口打开

<a href="javascript:" onClick="window.open('login.do','','height=500,width=611,scrollbars=yes,status=yes')">新窗口</a>


第五种:通过meta设置跳转页面

<head>
     <!--只刷新不跳转 -->
     <meta http-equiv="refresh" content="5">
     <!--定时跳转 -->
     <meta http-equiv="refresh" content="5;url=index.html"> 
 </head>

这里还有一个页面传值

第一个页面
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>无标题文档</title>
 </head>
 <SCRIPT LANGUAGE="JavaScript">
     function test(){
         var s = document.getElementById("txt");
         location.href="test2.html?"+"txt="+encodeURI(s.value);
     }
 </SCRIPT>
 <body>
  
 <input type="text" id="txt">
 </br>
 <input type="button" value="TEST" onclick="test()"/>
  
 </body>
 </html>
第二个页面
<head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>无标题文档</title>
 </head>
  
 <body>
   <script language="javascript" type="text/javascript">
   var loc = location.href;
   var n1 = loc.length;//地址的总长度
   var n2 = loc.indexOf("=");//取得=号的位置
   var id = decodeURI(loc.substr(n2+1, n1-n2));//从=号后面的内容
   alert(id);
   //document.write(id)
   </script>
 </body>
 </html>

文章出处登录后可见!

已经登录?立即刷新

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
心中带点小风骚的头像心中带点小风骚普通用户
上一篇 2023年12月11日
下一篇 2023年12月11日

相关推荐