Home  >  Article  >  Web Front-end  >  7 ways to use JS to jump to pages (share)

7 ways to use JS to jump to pages (share)

青灯夜游
青灯夜游forward
2021-01-28 19:09:243606browse

7 ways to use JS to jump to pages (share)

I believe many web developers know that when developing web programs, there are many ways to jump between pages, but effective jumps will get twice the result with half the effort. Here is what I do 7 JavaScript jump methods used in daily development.

The first type: jump directly with parameters

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

Jump directly without parameters:

<script>window.location.href=&#39;http://www.baidu.com&#39;;</script>

The second type: return to the previous One-time preview interface

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

Tag nesting:

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

Third type: Specifying the jump page is invalid for the frame

   <script language="javascript">
       window.navigate("top.jsp");
  </script>

The fourth way: specifying the self-jump page is invalid for the frame

   <script language="JavaScript">
          self.location=&#39;top.htm&#39;;
   </script>

The fifth way: specifying the self-jump page is valid for the frame

   <script language="javascript">
          alert("非法访问!");
          top.location=&#39;xx.aspx&#39;;
   </script>

Sixth type: Add event jump to button button

<input name="pclog" type="button" value="GO" onClick="location.href=&#39;login.aspx&#39;">

Seventh type: Open in new window

<a href="javascript:" onClick="window.open(&#39;login.aspx&#39;,&#39;
&#39;,&#39;height=500,width=611,scrollbars=yes,status=yes&#39;)">开新窗口</a>

Example:

<head> 
<script language="javascript">

function old_page() 
{ 
window.location = "login.aspx" 
} 
function replace() 
{ 
window.location.replace("login.aspx") 
} 
function new_page() 
{ 
window.open("login.aspx") 
} 
</script> 
</head> 
<body> 
<input type="button" onclick="new_page()" value="在新窗口打开s"/> 
<input type="button" onclick="old_page()" value="跳转后有后退功能"/> 
<input type="button" onclick="replace()" value="跳转后没有后退功能"/> 
</body>

For more programming-related knowledge, please visit: Programming Teaching! !

The above is the detailed content of 7 ways to use JS to jump to pages (share). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete