0

假设我在一个页面上有一个名为“点击下载”的锚标签,点击该标签会下载一个 csv 文件

HTML代码是

<span id="tag_id">
    <a class="classA" onclick="calling_an_excel_function()" href="#"> Click here to download all records.</a>
</span> 

实际上它是调用 Javascript Onclick 函数并生成一个 csv 文件,onclick 函数的代码是

function calling_an_excel_function() {
    var exampleA = document.getElementById('exampleA.value');
    var exampleB = document.getElementById('exampleB.value');
    var exampleC = document.getElementById('exampleC.value');
    var exampleD = document.getElementById('exampleD.value');
    window.open('indices_main_excel.aspx?ind=' + exampleA.value + '&fromDate=' + exampleB.value + '&toDate=' + examplec.value + '&DMY=' + exampleD.value, '_blank',
'toolbar=yes,location=no, directories=no, status=no, menubar=yes,scrollbars=yes, resizable=yes ,copyhistory=no, width=800, height=600');
} 

我可以预期在 onclick 函数中window.open()方法正在生成一个新文件,并给出了一些值。现在我无法从上面的 onclick 函数中获取csv文件下载url我可以知道如何获取 csv 文件下载链接吗

4

2 回答 2

0

(只是猜测)

但你可能想要

document.getElementById('exampleA');

代替

document.getElementById('exampleA.value');
于 2012-04-24T14:17:21.393 回答
0

您不需要使用 Window.open。将 href 更改为等于文件路径(是的,它来自您的服务器代码)或使用 window.location。确保您设置了 content-disposition 标头。

我不知道如何在 python 中设置标头,但您需要设置一个如下所示的标头:

内容处置:附件;文件名="文件名.csv"

于 2012-04-24T14:19:38.620 回答