← coderrocketfuel.com

Open a URL in a New Window Using Purely JavaScript

How can you open a URL in a brand new window using JavaScript in your application?

You can do this via the window.open() method:

const URL = "https://www.google.com";
const windowProperties = "location=yes,height=800,width=800,scrollbars=yes,status=yes";

window.open(URL, "_blank", windowProperties);

As an example, that will open the Google homepage in a new browser window.

The third parameter for window.open() is where you specify the window properties, such as height, width, if it should have scrollbars, etc.

You can read more about the window.open() method here.

Thanks for reading and happy coding!