Home > Web Front-end > JS Tutorial > Several common ways to implement page jumps in JavaScript_javascript skills

Several common ways to implement page jumps in JavaScript_javascript skills

WBOY
Release: 2016-05-16 15:29:15
Original
1221 people have browsed it

The examples in this article describe several common ways to implement page jumps in JavaScript. Share it with everyone for your reference, the details are as follows:

First type:

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

Copy after login

Second type:

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

Third type:

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

The fourth type:

<script language="JavaScript">
    self.location='top.htm';
</script>
Copy after login

The fifth type:

<script language="javascript">
    alert("非法访问!");
    top.location='xx.jsp';
</script>
Copy after login

Pop up the selection box in javascript to jump to other pages

<script language="javascript">
<!--
function logout()...{
if (confirm("你确定要注销身份吗?是-选择确定,否-选择取消"))...{
window.location.href="logout.asp&#63;act=logout"
}
}
-->
</script>
Copy after login

The prompt box pops up in javascript to jump to other pages

<script language="javascript">
<!--
function logout()...{
alert("你确定要注销身份吗?");
window.location.href="logout.asp&#63;act=logout"
}
-->
</script>
Copy after login

Additional: What is the difference between window.location=""; and location.replace("");?

Both of these can direct the web page to a URL, so what is the difference? For example, parameters can be taken, parameters cannot be taken, etc.
Replace? Or Reload()?
There seems to be no difference, right? Never tried it

replace(), reload() is to reload this page, and replace() can lead to another URL

Let me give you an example:

We now have 3 pages (a.html, b.html, c.html).
The a.html page is opened by default, and then a link is directed to the a.html page in the a.html page.

Now, I use window.location.replace("c.html"); and window.location.href("c.html"); in the b.html page to enter the c.html page respectively.

There is no difference from the user interface, but now the c.html page has a "Back" button,
Use window.location.href("c.html");

When entering the c.html page, call window.history.go(-1);wondow.history.back(); when entering the c.html page, click the "Back" button If you return to the b.html page,
And if you use window.location.replace("c.html"); to enter the c.html page,
The calling window.history.go(-1);wondow.history.back(); method in the c.html page is not easy to use and will return to a.html.

Because window.location.replace("c.html"); does not send a request to the server and jumps, but the window.history.go(-1);wondow.history.back(); method is based on the server record The request determines which page to jump to, so it will jump to the system default page a.html.

window.location.href("c.html"); is a jump to send a request to the server, window.history.go(-1);wondow.history.back(); method is based on the request recorded by the server Decide which page to jump to, so you can return to b.html.

I hope this article will be helpful to everyone in JavaScript programming.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template