Categories
JavaScript Answers

How to load a page on button click with JavaScript?

Spread the love

Sometimes, we want to load a page on button click with JavaScript.

In this article, we’ll look at how to load a page on button click with JavaScript.

How to load a page on button click with JavaScript?

To load a page on button click with JavaScript, we can use window.open.

For instance, we write

<button
  type="button"
  onclick="window.open('http://www.example.com/', '_blank');"
>
  View Example Page
</button>

to call window.open with the URL to open and '_blank' to open it in a new window.

We set the code as the value of the onclick attribute to open the window when we click it.

Conclusion

To load a page on button click with JavaScript, we can use window.open.

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 *