Copy link to clipboard
Copied
When applying a link action to a button, I cannot get it to open in a new window/tab:
<button onclick="window.location.href='https://google.com';" target="_blank" type="button" class="btn btn-outline-primary btn-lg ctaBtn" style="margin-top: 1em;">Request Sample</button>
Can you please advise what must be applied to get the button link to open in a new window/tab?
Thanks.
Copy link to clipboard
Copied
Are you using Bootstrap? With all of those button classes, why not just change the button --> a and just have a stylized link that looks like a button? Then you can remove the javascript and use a href value.
Copy link to clipboard
Copied
Adding to @r_tist's reply, the code would look like
<a href="https://google.com" class="btn btn-outline-primary btn-lg mt-4" target="_blank">Request Sample</a>
This code is semantically more correct than using a button element because of the following statements:
Copy link to clipboard
Copied
Thank you for this clear explanation!
Very good.
Copy link to clipboard
Copied
FYI: JavaScript uses different terms & syntax. For details, see below.
https://www.geeksforgeeks.org/how-to-open-url-in-new-tab-using-javascript/#