This tutorial will help you to redirect a webpage to another webpage using JavaScript. Here are 3 examples of redirecting webpage to another with JavaScript. Example 1: We can redirect user to other page using window.location.replace in JavaScript. window.location.replace has pretty similar to an HTTP redirect.
1 | window.location.replace("https://example.com"); |
Example 2: It is better to use window.location.href in place of window.location.replace, because replace() function does not put the originating page in the session history.
1 | window.location.href = "https://example.com"; |
Example 3: We can also simply redirect to any internal website page using window.location.
1 | window.location.href = "/other-page/"; |