使用Javascript函数启动下载 [英] Initiate downloads with a Javascript function
问题描述
我有多个网址供用户下载。下载应在他们点击赞或发布推文后触发。我已经成功设置了两者的回调函数。
I have multiple URLs for users to download. The download should be triggered after they hit "Like" or post a "Tweet". I have successfully setup the callback functions for both.
我想知道如何使用Javascript以便同时触发多次下载。一种解决方案是使用 window.location
,但这只会触发单次下载。我甚至可以做多个 window.open
但是弹出窗口阻止程序会阻止这个。
I wish to know how do I employ Javascript so that the multiple downloads are triggered simultaneously. One solution would be to use window.location
, but that would trigger just single download. I can even do multiple window.open
but the pop-up blocker would block this.
还有什么其他选择呢?我有这种情况吗?
What other alternatives do I have for this situation?
推荐答案
你可以做的是为每次下载创建一个隐藏的iframe文件的src,如:
What you can do is create a hidden iframe with the src of the file for each download, something like:
function download(url){
var iframe = document.createElement("iframe");
iframe.src = url;
iframe.style.display = "none";
document.body.appendChild(iframe);
}
这篇关于使用Javascript函数启动下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!