admin管理员组文章数量:1425789
My goal is to let a user download a PDF from my server. The most mon approach to this would be to simply have a link with a download attribute like so
<a href="" download>click here</a>
The problem with this is that I cannot monitor the download or have a callback when it is finished. The browser just hangs until the request is processed and suddenly pops up a download when it is done.
So now I am getting pdf data from a server with AJAX and want to download the data via the browser.
So I have something along the lines of
$.get("", (data) ->
#need to somehow trigger a download with this data
)
I've been searching for a while to no avail. Any help is appreciated. Thanks!
--edit To clarify why this is not a duplicate, I am asking about triggering a download on data, not a local file.
My goal is to let a user download a PDF from my server. The most mon approach to this would be to simply have a link with a download attribute like so
<a href="http://mysource.pdf" download>click here</a>
The problem with this is that I cannot monitor the download or have a callback when it is finished. The browser just hangs until the request is processed and suddenly pops up a download when it is done.
So now I am getting pdf data from a server with AJAX and want to download the data via the browser.
So I have something along the lines of
$.get("http://mysource.pdf", (data) ->
#need to somehow trigger a download with this data
)
I've been searching for a while to no avail. Any help is appreciated. Thanks!
--edit To clarify why this is not a duplicate, I am asking about triggering a download on data, not a local file.
Share Improve this question edited Jul 10, 2015 at 21:22 tbogatchev asked Jul 10, 2015 at 21:09 tbogatchevtbogatchev 1,6513 gold badges15 silver badges22 bronze badges 3- Possible duplicate – ODelibalta Commented Jul 10, 2015 at 21:12
- search "monitor download progress with javascript" Most solutions seem to require server-side intervention. – Kevin B Commented Jul 10, 2015 at 21:13
- I would like to point out that this is NOT a duplicate of the linked thread. That thread is asking about downloading a file. I am downloading data. – tbogatchev Commented Jul 10, 2015 at 21:17
1 Answer
Reset to default 4$('a').click(function(event) {
event.preventDefault();
$.get("http://mysource.pdf", (data) ->
window.location.href = $(this).attr('href');
)
});
本文标签: javascriptTrigger a browser download with JQueryStack Overflow
版权声明:本文标题:javascript - Trigger a browser download with JQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745430512a2658302.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论