JavaScriptEasy
How do you redirect to a new page in JavaScript?
By FrontendPro Editorial Team Updated 8/8/2026
#JavaScript
Answer
To redirect to a new page in JavaScript, you can use the window.location object. The most common methods are window.location.href and window.location.replace(). For example:
js
// Using window.location.href
window.location.href = "https://www.example.com";
// Using window.location.replace()
window.location.replace("https://www.example.com");
