简体   繁体   English

不知道如何在代码中使用 target="_blank"

[英]Don't know how to use target="_blank" in code

I currently use a download button whose HTML and Script is like this我目前使用的下载按钮的 HTML 和脚本是这样的

<button id="downloadbuttonx" onclick="generate()"><i aria-hidden="true" class="fa fa-cloud-download"></i> Download</button>
<a href="https://www.google.com" id="downloadingx" style="display: none;"><i aria-hidden="true" class="fa fa-cloud-download"></i> Redirecting...</a> Script

<script type='text/javascript'>
  //<![CDATA[
  function generate() {
    var e, n = document.getElementById("downloadingx"),
      t = document.getElementById("downloadbuttonx"),
      a = document.getElementById("downloadingx").href,
      l = 4,
      d = document.createElement("span");
    n.parentNode.replaceChild(d, n), e = setInterval(function() {
      --l < 0 ? (d.parentNode.replaceChild(n, d), clearInterval(e), window.location.replace(a), n.style.display = "inline") : (d.innerHTML = "<i class='fa fa-clock-o' aria-hidden='true'/> Redirecting to download page in " + l.toString() + " seconds.", t.style.display = "none")
    }, 1e3)
  }
  //]]>
</script>

It works like, When download button is clicked, 4 seconds timer began and when finished, Link is opened in the same page.它的工作原理是,当点击下载按钮时,4 秒计时器开始,完成后,链接在同一页面中打开。

I want that link to be opened in a new Tab, instead of a same page and I have no idea how to do it.我希望该链接在新选项卡中打开,而不是在同一页面中打开,但我不知道该怎么做。

Please help.请帮忙。

要将行为从重定向页面更改为打开新选项卡,请将代码中的window.location.replace(a)更改为window.open(a)

The target="_blank" is an attribute that corresponds to an "a" element. target="_blank" 是对应于“a”元素的属性。 It triggers the link to be opened in a new tab if the link element is clicked.如果单击链接元素,它会触发在新选项卡中打开链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM