[英]How can I download a list of files dynamically generated with javascript?
I'm trying to create and loop through a list of links that point towards a dynamically generated XML file. 我正在尝试创建并循环访问指向动态生成的XML文件的链接列表。
Here is the code I'm using . 这是我正在使用的代码。 .
。 .
。 I've changed the url:
我已经更改了网址:
function scanSystem() {
// Starting value for scans
var xMin = '0';
var yMin = '0';
// Temporary - The highest coordinates that will be scanned
var coordMax = '19';
for (var x = xMin; x <= coordMax; x++) {
for (var y = yMin; y <= coordMax; y++) {
var url = "http://www.xmlurl.com/members/scanners/list.php?cockpit&xml&x=" + x + "&y="+ y;
var link = "<a href='" + url + "'>(" + x + "," + y + ")</a><br>";
$("#links_container").append(link);
document.getElementById('iframe').src = url;
}
}
}
The links generate and fill the div (which is more of a debug function at the moment) but only the last link is actually downloaded through the iframe. 这些链接会生成并填充div(目前更多是调试功能),但实际上只有最后一个链接是通过iframe下载的。
Any ideas how to make it start the download of the other files as well? 有什么想法可以使它也开始下载其他文件吗?
Rather than opening the URLs in an iframe, just open them with window.open
. 与其在iframe中打开URL,不如通过
window.open
打开它们。 Most browsers will immediately close the new window if it only downloads a file. 如果仅下载文件,大多数浏览器将立即关闭新窗口。
A way to do it is to dynamically create a hidden iframe
for each link instead of opening new windows (which will be annoying). 一种方法是为每个链接动态创建一个隐藏的
iframe
,而不是打开新窗口(这会很烦人)。 Each iframe will be loading each file individually. 每个iframe将分别加载每个文件。
Taking advantage that you are using jQuery already, here's sample code: 利用您已经在使用jQuery的优势,这里是示例代码:
function scanSystem() {
var x
, y
, coordMax = 19
, url
, linksContainer = $("#links_container")
;
for (x = 0; x <= coordMax; x++) {
for (y = 0; y <= coordMax; y++) {
url = 'http://www.xmlurl.com/members/scanners/list.php?cockpit&xml&x=' + x + '&y=' + y;
$('<a/>',{
href : url
})
.text(x+','+y)
.appendTo(linksContainer);
$('<iframe/>',{
src : url
})
.appendTo('body');
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.