Home  >  Article  >  Web Front-end  >  How to jump to a new page in javascript

How to jump to a new page in javascript

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-04-13 17:58:0621212browse

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

How to jump to a new page in javascript

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!

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