【发布时间】:2021-01-16 13:28:09
【问题描述】:
我目前使用一个下载按钮,其 HTML 和 Script 是这样的
<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) -
嘿,罗里·麦克罗桑!太感谢了。 ☺♥ 这对我有用。 ☺♥非常感谢☺♥
-
很高兴它有帮助。我为你添加了答案
标签: javascript html jquery css json