HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavascriptCritical

How to get the browser to navigate to URL in JavaScript

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
browserhowurlthenavigatejavascriptget

Problem

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?

Solution

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

Code Snippets

window.location.href = '...';
window.location.replace('...');

Context

Stack Overflow Q#1226714, score: 1973

Revisions (0)

No revisions yet.