Button to open a new window in html
To create a button that opens a new window in HTML, you can use the <a>
tag with the target
attribute set to _blank
. Here is an example:
<a rel="nofollow" target="_blank" href="https://www.example.com" target="_blank">Open in new window</a>
This will create a link that opens the specified URL in a new window or tab when clicked.
Alternatively, you can use the <button>
tag with the onclick
attribute to achieve the same result:
<button onclick="window.open('https://www.example.com', '_blank')">Open in new window</button>
This will create a button that, when clicked, opens the specified URL in a new window or tab.
You can also use the window.open()
method to open a new window programmatically:
<button onclick="window.open('https://www.example.com', '_blank')">Open in new window</button>
This will create a button that, when clicked, opens the specified URL in a new window or tab.
Note that the _blank
value for the target
attribute or the second argument to the window.open()
method specifies that the link should be opened in a new window or tab. You can also use other values, such as _self
to open the link in the same window, or _parent
to open the link in the parent frame.