【问题标题】:how can my button open a new tab? [duplicate]我的按钮如何打开一个新标签? [复制]
【发布时间】:2018-05-20 00:15:39
【问题描述】:

我有一个基本的 jquery 问题。只是试图使此链接在新选项卡/窗口中打开。我添加了 _blank 但它没有转到新页面。有什么想法吗?

   $('#link13').click(function() {

    window.location.href= 'https://www.google.com','_blank';

  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button type="button" class="btn btn-primary" id="link13">See the Resources</button>

【问题讨论】:

  • 试试window.open('https://www.google.com','_blank');

标签: jquery


【解决方案1】:

在 HTML 中,您可以使用以下内容:

&lt;button class="btn btn-success" onclick=" window.open('http://google.com','_blank')"&gt; Google&lt;/button&gt;

纯 HTML 方法:

&lt;a href="https://google.com" target="_blank"&gt;Google&lt;/a&gt;

【讨论】:

    【解决方案2】:
    $('#link13').click(function() {
        window.open(
          'https://www.google.com',
          '_blank' // <- This is what makes it open in a new window.
        );
    });
    

    【讨论】:

      【解决方案3】:

      使用window.open():

      var win = window.open('https://www.google.com','_blank');
      if (win) {
          //Browser has allowed it to be opened
          win.focus();
      } else {
          //Browser has blocked it
          alert('Please allow popups for this website');
      }
      

      取决于浏览器的实现,这将起作用 看看这个是否有帮助..

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-02-12
        • 2021-12-06
        • 2014-07-28
        • 2021-01-24
        • 2019-05-18
        • 1970-01-01
        • 2015-12-13
        • 1970-01-01
        相关资源
        最近更新 更多