我有一个gridview,其中我有一列用于下载每行的pdf文件。 我启动了一个javascript函数,它使用“window.location.href”从另一个页面创建和下载PDF文件。 现在在Clientclick上点击某个按钮,我调用了一个javascript函数,其中for循环读取gridview的每一行和fire click事件(我在网格中用来下载PDF的按钮),用于一次性下载多个PDF文件行。 通过使用这种技术,我只获得带有最后一行详细信息的PDF,即在每行触发点击事件后只获得一个PDF。
答案 0 :(得分:1)
我执行以下操作:
theBuffer = new exchanger('dwnld');
创建一个javascript函数,只要您想启动文件下载,就可以调用它 :
function downloadFile(){
// you can add parameters to the function as needed to pass in dynamic data sent to the back end download handler
data = "http://your_backend_file_download_handler.php?param1=val1¶m2=val2&etc=whatever"; // send whatever data you need to the php program via query string parameters
theBuffer.sendData(data); // initiate the file download
}
注意:处理请求的php后端文件下载程序可以对您发送的参数执行任何操作,以便汇总/检索正确的数据/文件以供下载。经过多次修修补补后,this combination始终适用于我
在您的身体部分包含这一点html。我通常把它放在关闭身体标签之前:
<iframe name="dwnld" id="dwnld" style="width:0;height:0;border:0">
</iframe>
Note: the id value assigned to the iframe is the same value given in step 2 when initializing.
结果是用户永远不会离开当前页面下载任意数量的文件,因为实际下载是在单独的页面(也就是iframe)中处理的。多年来,我在所有项目中都毫无问题地使用了它。