【问题标题】:input onclick new tab输入onclick新标签
【发布时间】:2013-05-23 02:45:54
【问题描述】:
<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>

我正在使用以下内容制作下拉列表,只是想知道如何在新选项卡中而不是在其自己的窗口中打开选定选项

工作正常,因为它只需要在新标签页中打开。

* 编辑 *

这在需要时起作用了,谢谢

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

【问题讨论】:

  • target="_blank" 在标签页而不是新窗口中打开页面
  • with html 我使用 target="_blank" 不知道如何在你的情况下应用它

标签: html onclick


【解决方案1】:

试试window.open

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

更新

现场演示 - http://jsfiddle.net/im4aLL/tzp4H/

【讨论】:

  • 将在新窗口中打开,而不是新标签页
【解决方案2】:
function open_in_new_tab(url )
{
  var win=window.open(url, '_blank');
  win.focus();
}

当您想在新标签页中打开链接时调用该函数。还要检查herehere

【讨论】:

  • 重复的问题,重复的(和不正确的)答案。如果浏览器(比如 IE)禁用了 Tabbed Browsing,则这是不可能的。
【解决方案3】:

关于您对原始帖子的更新答案:

.value 之后添加,'_blank',如下所示:

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

实际上是在新标签页中打开,而不是在全新的浏览器窗口中打开。

【讨论】:

    【解决方案4】:

    没有高级或类似的东西。您只需要添加 _blank,如下例所示。

      <a href="someLink.html" target="_blank">
          <button>Visit my Github</button>
      </a>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-06-28
      • 1970-01-01
      • 2013-03-13
      • 1970-01-01
      • 1970-01-01
      • 2016-03-09
      • 1970-01-01
      相关资源
      最近更新 更多