Most often from an HTML page when you need to navigate the user to a different page it will be done via an anchor tag (
document.location in the HTML DOM, but it supports a couple more features than most developers are aware of.
document.location = '';
The behavior of this method of navigation is identical to a user clicking on an anchor (
<a>) tag within the page. This navigates to the new URL an leave both in the history, so the browsers back button works to go back to the previous page after navigating to the new URL.
Page Navigation Without Back Button Support
A feature of “document.location” that isn’t the most widely known is the ability to basically replace (or swap out) the current page with a new URL.
The behavior of this method of navigation is a bit different than the previous. Using the
document.location.replace method will cause the browser to replace the current page with the new URL. This essentially navigates to the new URL while removing the previous URL from the browser history. After navigating using this method, the browser back button will no longer bring the user back to the previous URL.
Using this method of navigating can be useful if you have a web application where the application may break or behave in an unexpected way when allowing the back button to function with it’s default behavior. This essentially gives you an option to disable the browsers back button for your website or application.
Reload the Current Page
Reloading the current page isn’t normally considered a method of “page navigation”, however, with web applications this may give you a desired behavior that could reset the current state of the page.
location.reload method accepts a single boolean parameter that determines if the page is forced to reload from the web server (if
true), or if it’s allowed to load from cache (if
- 01 Jul 2020
- 06 Apr 2020
- 02 Jan 2020
- 24 Jul 2019
- 10 Oct 2020
- 01 Jul 2020
- 06 Apr 2020
- 11 Mar 2020
- 15 Feb 2020
Recent on Build5Nines.com
- 04 Dec 2020
Latest Cloud News: Apple on K8s, IoT, Microsoft Pluton and more! (November 20, 2020 Build5Nines Weekly)20 Nov 2020
Latest Cloud News: .NET 5 Released, Apple Silicon M1 CPU, and more! (November 12, 2020 Build5Nines Weekly)12 Nov 2020
- 11 Nov 2020
Latest Cloud News: Kubernetes, Terraform, Teams Multi-Login and more! (November 5, 2020 Build5Nines Weekly)05 Nov 2020
This site is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com. We also participates in affiliate programs with Udemy, and other sites. This site is compensated for referring traffic and business to these companies.