Button html onclick link new window

To create a button in HTML that opens a new window when clicked, you can use the onclick attribute and the window.open() method. Here is an example:

<button onclick="window.open('https://www.example.com', '_blank')">Click me!</button>

In this example, the onclick attribute is used to specify a JavaScript event handler that will be executed when the button is clicked. The event handler is a string that calls the window.open() method, which opens a new window and loads the specified URL (https://www.example.com in this case).

The _blank parameter specifies that the new window should be opened in a new tab or window, rather than replacing the current one.

You can also add additional parameters to the window.open() method to customize the new window, such as:

For example:

<button onclick="window.open('https://www.example.com', '_blank', 'width=400,height=300,toolbar=yes,menubar=yes,scrollbars=yes')">Click me!</button>

This would open a new window with a width of 400 pixels, a height of 300 pixels, a toolbar, a menubar, and scrollbars.

Note that the window.open() method returns a reference to the new window, which can be useful if you need to interact with the new window programmatically. For example:

<button onclick="var newWindow = window.open('https://www.example.com', '_blank'); newWindow.focus()">Click me!</button>

This would open a new window and then focus on it, so that the user can interact with it immediately.