Wednesday 18 September 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...