Jumping to a new HTML page with JavaScript

javascript

You can jump to a new HTML page with JavaScript by using the window.location object.

Here’s an example code snippet that demonstrates how to do this:

// Navigate to a new page
window.location.href = "newPage.html";

In this example, the window.location.href property is set to the URL of the new page that you want to navigate to. This will cause the browser to load the new page, effectively “jumping” to it.

Alternatively, you can also use the window.location.replace() method to navigate to a new page:

// Navigate to a new page and replace the current page in the history
window.location.replace("newPage.html");

This method has the added benefit of replacing the current page in the browser history, meaning that clicking the browser’s “back” button will take the user back to the page that they were on before the current page.