[英]How to start download a file after window.open(url, _blank)
what i need is:我需要的是:
Now, this is my code现在,这是我的代码
<script type="text/javascript">
function DownloadAndRedirect()
{
var DownloadURL = "url-of-the-file";
var RedirectURL = "url-of-thank-you-page";
var RedirectPauseSeconds = 2;
location.href = DownloadURL;
setTimeout(DoTheRedirect(+RedirectURL+),parseInt(RedirectPauseSeconds*1000));
}
function DoTheRedirect(url) { window.location=url; }
</script>
Can you provide the correct code?你能提供正确的代码吗? i know i can use window.open...but how?
我知道我可以使用 window.open...但是怎么做呢?
Thanks谢谢
You are not using the setTimeout
correctly.您没有正确使用
setTimeout
。 You need to pass the thanksyou
page url and set the seconds to 2000
which are equivalent to 2
seconds.您需要通过
thanksyou
page url 并将秒数设置为2000
,相当于2
秒。
In setTimeout
use window.open
with a target _blank
so that it opens in a new tab
.在
setTimeout
中,将window.open
与目标_blank
一起使用,以便它在新tab
中打开。
Live Demo: (Code tested and its working on localhost)现场演示:(代码测试并在本地主机上运行)
function DownloadAndRedirect() { var DownloadURL = "https://www.google.com/"; var RedirectURL = "https://www.google.com/"; location.href = DownloadURL; setTimeout(function() { window.open(RedirectURL, '_blank') }, 2000) } DownloadAndRedirect()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.