Home > Web Front-end > JS Tutorial > How to jump to a specific page in js?

How to jump to a specific page in js?

青灯夜游
Release: 2020-10-29 09:07:44
Original
10945 people have browsed it

Jump method: 1. Use the "location.href="URL of the specified page";" statement to jump; 2. Use the "location.replace("URL of the specified page");" statement to jump ;3. Use the "location.assign("URL of the specified page");" statement to jump.

How to jump to a specific page in js?

Recommended tutorial: "JavaScript Video Tutorial"

Method 1: Use window. Location.href method to jump

This method can directly jump to the specified page.

<script type="text/javascript">
window.location.href = "https://www.php.cn";
</script>
Copy after login

window can be omitted and can be abbreviated as:

location.href="URL"
Copy after login

Method 2: Use the window.loction.replace method to jump

Syntax:

window.location.replace("url")
//可简写为
location.replace("url")
Copy after login

Replace the address with a new url. This method is specified by The URL replaces the item currently cached in the history (client), so after using the replace method, you cannot access the replaced URL through "forward" and "back". This feature is very useful for making some transition pages!

Example

<script type="text/javascript">
window.location.replace("https://www.php.cn")
</script>
Copy after login

Method 3: Use location.assign method to jump

assign() method Load a new document.

Syntax:

location.assign(URL)
Copy after login

Example:

<script type="text/javascript">
window.location.assign("https://www.php.cn")
</script>
Copy after login

Method 4: Use window.navigate method Jump

Syntax:

window.navigate("url");
Copy after login

The navigate object contains information about the browser, and can also be used as a page jump. Add the required information directly afterwards. Where to jump.

Example:

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

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

The above is the detailed content of How to jump to a specific page in js?. For more information, please follow other related articles on the PHP Chinese website!

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