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 blog post is licensed under the Creative Commons Attribution 3.0 United States License, unless explicitly stated otherwise within the blog post content. All other content on this website is not licensed under Creative Commons licensing.