Home >Web Front-end >JS Tutorial >How to control page jump with javascript

How to control page jump with javascript

青灯夜游
青灯夜游Original
2021-06-08 11:41:452584browse

Method: 1. Use "window.location.href="page address""; 2. Use the "window.history.back()" statement; 3. Use the "window.navigate()" statement; 4. Use the "self.location="address"" statement.

How to control page jump with javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

Several ways to implement page jump in Javascript

The first one: jump directly and add parameters

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

directly Jump without parameters:

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

Second: Return to the last 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: The specified jump page is invalid for the frame. . .

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

The fourth way: specifying the own jump page is invalid for the frame. .

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

Application examples:

<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 Video! !

The above is the detailed content of How to control page jump with javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn