So this is the simple code for the button to open a certain link
<button class="btn btn-success" onclick="location.href='http://google.com';"> Google</button>
but it opens it on the same page, I want the link to open on a new tab though.
Try this code.
Use '_blank'. It will not only open the link in a new tab but the state of the original webpage will also remain unaffected.
You can use the following.
in HTML
plunkr
Try using below code:
Here, the
window.open
with_blank
as second argument ofwindow.open
function will open the link in new tab.And by the use of
return false
we can remove/cancel the default behavior of the button like submit.With Bootstrap you can use an anchor like a button.
And use
target="_blank"
to open the link in a new tab.Try this