Home > Article > Web Front-end > How to implement webpage jump in javascript (code example)
In JavaScript, there are many ways to jump to web pages. The following are common methods:
window.location. href can directly jump the current page to the specified URL. The code is as follows:
window.location.href = "http://www.example.com";
window.open to open a new window or tab. , and jump to the specified URL, the code is as follows:
window.open("http://www.example.com", "_blank");
Among them, "_blank" means opening the link in a new window or tab.
location.replace can jump to the specified URL, and can also replace the current page so that it no longer appears in the browser's history. The original page, the code is as follows:
location.replace("http://www.example.com");
Since the current page is replaced, it is recommended to confirm the user operation before performing the jump operation.
In HTML, you can use form submission to jump to the specified URL. The code is as follows:
<form action="http://www.example.com" method="get"> <input type="submit" value="跳转"> </form>
Through the form The action attribute in specifies the jump URL, which automatically jumps when the form is submitted.
Summary
The above are several ways to jump to web pages in JavaScript. Which method to use needs to be chosen according to specific needs. Among them, window.location.href, window.open, and location.replace can be called directly in JavaScript, while the form needs to be used in HTML.
The above is the detailed content of How to implement webpage jump in javascript (code example). For more information, please follow other related articles on the PHP Chinese website!