javascript tutorial - [Solved-3 Solutions] How to get browser to navigate to URL in javascript - javascript - java script - javascript array




Problem:

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

Solution 1:

This works in all browsers:

window.location.href = '...';
click below button to copy the code. By JavaScript tutorial team

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

window.location.replace('...');
click below button to copy the code. By JavaScript tutorial team

Solution 2:

Try these:

  • window.location.href = 'http://www.google.com';
  • window.location.assign("http://www.wikitechy.com");
  • window.location = 'http://www.google.com';

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

Solution 3:

It seems that this is the correct way window.location.assign("http://www.mozilla.org");


Related Searches to javascript tutorial - How to get browser to navigate to URL in javascript