I would like to have a button that redirects to a given URL and opens in a new tab. How can this be done?
15 Answers
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;"

- 3,198
- 1
- 23
- 34
-
3@wong2 Might want to change answer to this one. The one currently selected is far to wordy to be efficient. – CSS Sep 25 '15 at 23:02
Adding target="_blank" should do it:
<a id="myLink" href="www.google.com" target="_blank">google</a>

- 62,884
- 17
- 92
- 129
-
3I see, sorry I've missed that. Well, you could style the link to look and feel like a button. If you're using jQuery UI just use [button](http://jqueryui.com/demos/button/) to do so. – Tim Büthe Jun 10 '11 at 09:12
-
1Excellent solution for the vast majority of us who merely dabble in web design! Thank you! – SMBiggs Apr 04 '13 at 05:57
-
2+1 because you gave a good solution to those looking for a simple "open link in new tab" answer, if they aren't using a button. – user295583058 Dec 10 '15 at 21:00
-
-
+1, if something opens a page in new tab, it is logically a link, so `` tag is appropriate. Styles should be used to make it look like a button. – Kos May 09 '18 at 06:41
-
-
You can forget about using JavaScript because the browser controls whether or not it opens in a new tab. Your best option is to do something like the following instead:
<form action="http://www.yoursite.com/dosomething" method="get" target="_blank">
<input name="dynamicParam1" type="text"/>
<input name="dynamicParam2" type="text" />
<input type="submit" value="submit" />
</form>
This will always open in a new tab regardless of which browser a client uses due to the target="_blank"
attribute.
If all you need is to redirect with no dynamic parameters you can use a link with the target="_blank"
attribute as Tim Büthe suggests.

- 364
- 4
- 3
My preferred method has the advantage of no JavaScript embedded in your markup:
CSS
a {
color: inherit;
text-decoration: none;
}
HTML
<a href="http://example.com" target="_blank"><input type="button" value="Link-button"></a>

- 869
- 1
- 16
- 46
-
2
-
Prefer the `a input[type=button]` CSS selector instead of just `a` – RixTheTyrunt Jun 21 '22 at 17:09
Use window.open
instead of window.location
to open a new window or tab (depending on browser settings).
Your fiddle does not work because there is no button
element to select. Try input[type=button]
or give the button an id
and use #buttonId
.

- 164,175
- 21
- 332
- 312
Open in new tab using javascript
<button onclick="window.open('https://www.our-url.com')" id="myButton"
class="btn request-callback" >Explore More </button>

- 1,063
- 15
- 14
I just used target="_blank" under form tag and it worked fine with FF and Chrome where it opens in a new tag but with IE it opens in a new window.

- 119
- 2
- 6
-
1Whether a tab or window opens is determined by the user's browser options. I don't know about IE, but in most browsers the webpage cannot choose whether the link opens in a tab or a window, but the user can configure it. – joeytwiddle Feb 24 '14 at 07:12
In React or Javascript we can do:
<button onClick={() => window.open(url, "_blank")}> content </button>
To use an Anchor tag:
<a href="url" target="_blank" > content </a>

- 559
- 7
- 10
Use button as anchor tag
<button
target="_blank"
rel="noreferrer"
as="a"
href="https://example.com"
>
Open
</button>
Try this HTML:
<input type="button" value="Button_name" onclick="window.open('LINKADDRESS')"/>

- 16,831
- 17
- 68
- 94

- 13
- 1
<BUTTON NAME='my_button' VALUE=sequence_no TYPE='SUBMIT' style="background-color:transparent ; border:none; color:blue;" onclick="this.form.target='_blank';return true;"><u>open new page</u></BUTTON>
This button will look like a URL and can be opened in a new tab.

- 1
-
-
It's not a good idea (semantically speaking) to have a button to behave like a link. Instead, use the `a` tag. – Henrique Schreiner Sep 19 '16 at 18:49
USE this code
function openBackWindow(url,popName){
var popupWindow = window.open(url,popName,'scrollbars=1,height=650,width=1050');
if($.browser.msie){
popupWindow.blur();
window.focus();
}else{
blurPopunder();
}
};
function blurPopunder() {
var winBlankPopup = window.open("about:blank");
if (winBlankPopup) {
winBlankPopup.focus();
winBlankPopup.close()
}
};
IT works fine in Mozilla,IE and chrome on and less than 22 version; but doesn't work in Opera and Safari.

- 15,374
- 13
- 103
- 121

- 46
- 3
-
2
-
1USe this code is not really an answer and you have no motivation behind it. – Edeph Apr 14 '15 at 09:18
You can't. This behaviour is only available for plugins and can only be configured by the user.

- 9,642
- 1
- 25
- 25