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