Sometimes, we want to change the current URL with JavaScript.
In this article, we’ll look at how to change the current URL with JavaScript.
How to change the current URL with JavaScript?
To change the current URL with JavaScript, we set the document.location.href property to the new URL.
For instance, we write
document.location.href = newUrl;
to set document.location.href to newUrl to navigate to the new URL.
Conclusion
To change the current URL with JavaScript, we set the document.location.href property to the new URL.