How to Get the Browser to Navigate to Url in Javascript [Duplicate]

What is the best (correct, modern, cross-browser, safe) way to get a web browser to navigate to a URL of your choice using JavaScript?

3

This works in all browsers:

window.location.href = '...';

If you wanted to change the page without it reflecting in the browser back history, you can do:

window.location.replace('...');
4

Try these:

  1. window.location.href = '
  2. window.location.assign("");
  3. window.location = '

For more see this link: other ways to reload the page with JavaScript

4

It seems that this is the correct way window.location.assign("");

2
Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest