Home > Article > Web Front-end > How to jump to a new page in javascript
JS method to jump to a new page: 1. Use the "replace()" function to jump, the syntax is "window.location.replace("page address")"; 2. Use the href attribute to jump Turn, the syntax is "window.location.href = "Page Address"".
The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, Dell G3 computer.
JavaScript can use the following two methods to implement page jump redirection:
window.location.replace("url"): similar to HTTP redirection
Replace the address with a new url. This method replaces the item currently cached in the history (client) by specifying the URL. Therefore, after using the replace method, you cannot access the replaced item through "forward" and "back". URL, this feature is very useful for making some transition pages!
window.location.href="url": Similar to clicking the link of the a tag, jumps to the specified url
Example
// 类似 HTTP 重定向 window.location.replace("https://www.php.cn/") // 类似点击链接(a 标签) window.location.href = "https://www.php.cn/";
Recommended learning: javascript video tutorial
The above is the detailed content of How to jump to a new page in javascript. For more information, please follow other related articles on the PHP Chinese website!