I would like to have a button that redirects to a given URL and opens in a new tab. How can this be done?
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>
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
.
Open in new tab using javascript
<button onclick="window.open('https://www.our-url.com')" id="myButton"
class="btn request-callback" >Explore More </button>
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.
Try this HTML:
<input type="button" value="Button_name" onclick="window.open('LINKADDRESS')"/>
In javascript you can do:
window.open(url, "_blank");