Categories
JavaScript Answers

How to open URL in new window with JavaScript?

Spread the love

Sometimes, we want to open URL in new window with JavaScript.

In this article, we’ll look at how to open URL in new window with JavaScript.

How to open URL in new window with JavaScript?

To open URL in new window with JavaScript, we call window.open with '_blank'.

For instance, we write

window.open(
  url,
  "_blank",
  "location=yes,height=570,width=520,scrollbars=yes,status=yes"
);

to call window.open to open the url.

And we set the 2nd argument to '_blank' to make it open in a new window.

We then set the window’s height, width, scrollbars, and status bar options with the string in the 3rd argument.

Conclusion

To open URL in new window with JavaScript, we call window.open with '_blank'.

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 *