下载文件并重定向...或替代 [英] Download a file and redirect...or alternative
问题描述
用户填写表单。使用有效的表单,他们点击下载文件。我想要将它们重定向到另一个页面(例如, page2.html
)并启动下载。
Users fill out a form. With a valid form, they click to download a file. I would like to be able to redirect them to another page (e.g., page2.html
) AND initiate a download.
我不能在 page2.html
上启动下载,因为大多数浏览器会标记安全警告,如果下载链接是不要直接点击。
I can't initiate download on page2.html
because most browsers will flag security warnings if a download link isn't directly clicked on.
如何使用javascript或jquery完成这样的事情?显然以下不起作用,但这是为了说明目的:
How is something like this accomplished using javascript or jquery? Obviously the following doesn't work but it's meant for illustrative purposes:
document.getElementById("foo").onclick = function(){
window.location = "/download.exe";
window.location = "/page2.html";
}
推荐答案
您可以使用链接该文件和 onclick
触发不久之后到下一页。
You could use a link to the file and onclick
to trigger "go to the next page shortly".
<script>
function thanks() {
setTimeout(function () {
document.location.pathname = "page2.html";
}, 1000);
}
</script>
<a href="file.exe" onclick="thanks()">Download now!</a>
这篇关于下载文件并重定向...或替代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!