我正在创建一个在主页下载图标顶部的网站,当我单击该图标时,另一个页面将打开,显示消息,如感谢下载,2-3秒后下载将自动启动,我是如何做到这一点的。
发布于 2014-11-25 10:19:17
在显示消息的页面中,将<meta http-equiv="refresh" content="3;url=/download url" />放在<head>部分中。这将在3秒后将请求重定向到下载url。
发布于 2014-11-25 10:29:29
您需要准备下载页面,并附加一个超时脚本,允许它在2-3秒后下载。
在图标上添加onclick函数,如下所示:
<img id="downloadBtn" onclick="window.open('<put link to the download page here>')" />在下载页面中,添加脚本,如下所示:
<html>
<head>
<title>Download page</title>
</head>
<body>
<h1>Thank you for downloading</h1>
<p>Your download will start in <span id="countdown">5</span> seconds</p>
<script type="text/JavaScript">
var countdown = document.getElementById("countdown");
var wait = 5;
var timeout = setInterval(function(){
wait--;
countdown.innerHTML=wait;
if (wait == 0){
clearInterval(timeout);
location.href="<link to the download file goes here>";
}
},1000);
</script>
</body>
</html>https://stackoverflow.com/questions/27123889
复制相似问题