I would like to have a button that redirects to a given URL and opens in a new tab. How can this be done?
Method 1: Ctrl+Click The first method requires a keyboard and a mouse or trackpad. Simply press and hold the Ctrl key (Cmd on a Mac) and then click the link in your browser. The link will open in a new tab in the background.
You need to use the _blank value in the target attribute to open the linked URL in a new tab or window. If you want to open URL with JavaScript, the open() method of Window interface is the best option. The JavaScript window. open() method opens a new browser window.
To open a link in a new browser window, hold the Shift on then click the link or right-click the link and select Open link in New Window.
Use this:
<input type="button" value="button name" onclick="window.open('http://www.website.com/page')" />
Worked for me and it will open an actual new 'popup' window rather than a new full browser or tab. You can also add variables to it to stop it from showing specific browser traits as follows:
onclick="window.open(this.href,'popUpWindow','height=400,width=600,left=10,top=10,,scrollbars=yes,menubar=no'); return false;"
In javascript you can do:
window.open(url, "_blank");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With