How to redirect to another webpage
- Previous Page Find Hidden Elements
- Next Page Format Numbers
Learn how to redirect to another webpage using JavaScript.
Redirect webpage
There are several methods to redirect to another webpage using JavaScript. The most popular one is location.href
and location.replace
:
Example
// Simulate mouse click: window.location.href = "http://www.codew3c.com"; // Simulate HTTP redirection: window.location.replace("http://www.codew3c.com");
Note:The difference between href and replace is replace()
The current document's URL will be deleted from the document history, which means you cannot navigate back to the original document using the 'Back' button.
Related Pages
Reference Manual:Location Object
- Previous Page Find Hidden Elements
- Next Page Format Numbers