Skip to content

Instantly share code, notes, and snippets.

@jens1101
Last active October 9, 2020 21:07
Show Gist options
  • Select an option

  • Save jens1101/525d0def2f458196a9f3c00eb52c1537 to your computer and use it in GitHub Desktop.

Select an option

Save jens1101/525d0def2f458196a9f3c00eb52c1537 to your computer and use it in GitHub Desktop.
The correct way to handle the browser location in JS
// 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