7
<form name="test">
<select name="choose" style="width:300px;">
<option selected="">Select option</option>
<option value="http://url.com">Test</option>
</select>
<input onclick="location=document.test.choose.options[document.test.choose.selectedIndex].value;" value="Take me there!" type="button"></p>
</form>

Im using the following to make a dropdown list and was just wondering how i would make selected open in a new tab and not in its own window

Works fine as it is just need it to open in a new tab.

* Edit *

This worked as needed thanks

<input onClick="window.open(document.test.choose.options[document.test.choose.selectedIndex].value);" value="Take me there!" type="button">
Dan Howes
  • 87
  • 1
  • 1
  • 5

4 Answers4

21

try window.open

window.open('http://www.google.com');

update

live demo - http://jsfiddle.net/im4aLL/tzp4H/

HADI
  • 2,829
  • 1
  • 26
  • 26
3
function open_in_new_tab(url )
{
  var win=window.open(url, '_blank');
  win.focus();
}

Call that function when you want to open a link in a new tab. Also check here and here

Community
  • 1
  • 1
imulsion
  • 8,820
  • 20
  • 54
  • 84
  • Duplicate question, duplicate (and incorrect) answer. This is not possible if the browser, let's say, IE, has [_Tabbed Browsing_](http://www.howtogeek.com/howto/windows-vista/disable-tabbed-browsing-in-internet-explorer-7/) disabled. – Alex Filipovici May 28 '13 at 08:20
2

Regarding your updated answer to your original post:

Adding ,'_blank' after the .value like so:

<input type="button" onClick="window.open(document.test.choose.options[document.test.choose.selectedIndex].value,'_blank');>

Actually opens in a new tab instead of an entirely new browser window.

gyrofly
  • 39
  • 2
0

Nothing advanced or similar. You just need to add _blank as the following example demonstrate.

  <a href="someLink.html" target="_blank">
      <button>Visit my Github</button>
  </a>
Rikki
  • 3,338
  • 1
  • 22
  • 34
Mujeeb Ishaque
  • 2,259
  • 24
  • 16