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

How to jump to a specific page in js?

青灯夜游
青灯夜游Original
2020-10-28 11:28:0911025browse

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>

window can be omitted and can be abbreviated as:

location.href="URL"

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

Syntax:

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

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>

Method 3: Use location.assign method to jump

assign() method Load a new document.

Syntax:

location.assign(URL)

Example:

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

Method 4: Use window.navigate method Jump

Syntax:

window.navigate("url");

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>

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!

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