Wednesday, September 18, 2019

How to get the browser to navigate to URL in JavaScript




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?


Answer



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('...');

No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...