Jumping to a new HTML page with JavaScript
javascriptYou 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.
Other Article on Tag javascript
- - Adding and removing content in jQuery
- - Are JavaScript strings immutable? Do I need a "string builder" in JavaScript?
- - Can I change the Dojo namespace to something other than dojo
- - Can I prevent user pasting Javascript into Design Mode IFrame
- - dynamically create html element in javascript
- - Find XY of an HTML element with JavaScript
- - How can I upload files asynchronously with jQuery
- - How can you display Typing Speed using Javascript or the jQuery library
- - How do you capture mouse events in firefox
- - How to auto-size an iFrame