簡體   English   中英

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

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

我目前使用的下載按鈕的 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>

它的工作原理是,當點擊下載按鈕時,4 秒計時器開始,完成后,鏈接在同一頁面中打開。

我希望該鏈接在新選項卡中打開,而不是在同一頁面中打開,但我不知道該怎么做。

請幫忙。

要將行為從重定向頁面更改為打開新選項卡,請將代碼中的window.location.replace(a)更改為window.open(a)

target="_blank" 是對應於“a”元素的屬性。 如果單擊鏈接元素,它會觸發在新選項卡中打開鏈接。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM