Categories
JavaScript Answers

How to change the location of the current web page using JavaScript?

Spread the love

Sometimes, we want to change the location of the current web page using JavaScript.

In this article, we’ll look at how to change the location of the current web page using JavaScript.

How to change the location of the current web page using JavaScript?

To change the location of the current web page using JavaScript, we set window.location.href to the URL we want to go to.

For instance, we write

window.location.href = 'URL';

to set window.location.href to the string with the URL we want to navigate to.

Conclusion

To change the location of the current web page using JavaScript, we set window.location.href to the URL we want to go to.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *