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

How to jump to a new page in javascript

醉折花枝作酒筹
Release: 2023-01-05 16:08:14
Original
21260 people have browsed it

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("//m.sbmmt.com/")
// 类似点击链接(a 标签)
window.location.href = "//m.sbmmt.com/";
Copy after login

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!

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