Last active
October 9, 2020 21:07
-
-
Save jens1101/525d0def2f458196a9f3c00eb52c1537 to your computer and use it in GitHub Desktop.
The correct way to handle the browser location in JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Source: https://developer.mozilla.org/en-US/docs/Web/API/Location | |
| // Source: https://developer.mozilla.org/en-US/docs/Web/API/Window/location | |
| // Navigate to a new page. | |
| window.location.assign('http://www.mozilla.org') | |
| // Force reloading the current page from the server | |
| // **Note:** If the parameter is not set or set to false then the browser may | |
| // reload from cache | |
| window.location.reload(true) | |
| // Replace the current page with another. | |
| // **Note:** This erases the current page from the browser history, so the user | |
| // will not be able to navigate back to it. | |
| window.location.replace('http://example.com') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment