document.location = '';
The behavior of this method of navigation is identical to a user clicking on an anchor () 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.
The “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 ‘false’).
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.