+ 1

How do you make an onclick open in a new tab

say for instance i have the following code: <button onclick="location.href='www.google.com'" target="_blank">Go to Google </button>

7th Nov 2016, 12:12 AM
umop ap!sdn
umop ap!sdn - avatar
3 Respuestas
+ 3
_blank makes it open in a new tab so i really dont get your question
7th Nov 2016, 12:40 AM
Rodrigo Tallar
Rodrigo Tallar - avatar
+ 1
not with a button and a onclick="location.href='random website'" it will open in the same tag
7th Nov 2016, 12:51 AM
umop ap!sdn
umop ap!sdn - avatar
+ 1
A couple of suggestions... 1. If you're good at CSS, replace <button> with <a> and style <a> to look like a <button>. 2. Use a hidden <a> and trigger its click event handler, when <button> is clicked. Example: https://jsfiddle.net/L6z5t84o/
7th Nov 2016, 1:21 AM
Michelle Edmondson
Michelle Edmondson - avatar