你下载的javascript多个PDF文件 [英] Dowloading multiple PDF files from javascript
问题描述
我有一个GridView中,我有一列用于下载的PDF文件的每一行。
我火了,它使用window.location.href创建并从另一个页面下载PDF文件JavaScript函数。
现在,一些按键Clientclick,我调用javascript函数,其中一个for循环读取GridView和火灾click事件中的每一行同时下载多个PDF文件的所有(这是我在网格中使用下载PDF按钮)行。
通过使用这种技术,我只得到PDF,只有最后一排的细节,这为m触发click事件的每一行后只得到一个PDF。
I have a gridview in which I have one column for downloading pdf files for each row. I fire a javascript function which uses "window.location.href" to create and download PDF file from another page. Now on Clientclick of some button ,I am calling a javascript function in which a for loop reads each line of gridview and fire click event (of the button which i used in grid to download PDF) for downloading multiple PDF files at once for all the rows. By using this technique I am only getting PDF with the details of last row only ,that is m getting only one PDF after firing click event for each row.
推荐答案
我做到以下几点:
- 提供 exchanger.js JavaScript文件在你的脑袋节
- 在初始化页面加载器对象:
theBuffer =新的交换器('DWNLD');
-
创建一个javascript函数,你会打电话每当你想启动一个文件下载
- Include the exchanger.js javascript file in your head section
- Initialize the exchanger object on page load:
theBuffer = new exchanger('dwnld');
Create a javascript function that you will call whenever you want to initiate a file download :
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的后端文件下载程序。经过一番摆弄这个组合是什么一直为我的作品
Note: The php back end file download program that handles the requests can do whatever it needs to do with the parameters you send it in order to put together/retrieve the correct data/file for download. After much tinkering this combination is what consistently works for me
包含HTML在你的身体部分这一点点。我通常把它刚刚结束标记之前:
Include this little bit of html in your body section. I usually put it just before the closing body tag:
<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)。我已经用它没有问题,我所有的项目很多年了。
The result is that the user never leaves the current page to download any number of files because the actual download is handled in a separate page (aka the iframe). I have used it without issue in all of my projects for years now.
这篇关于你下载的javascript多个PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!