admin管理员组文章数量:1426637
I have a jQuery plugin I use to dynamically create and render a form on a default.aspx asp page, then submit it. The page it gets submitted to is a pdf.aspx page. The page builds a PDF then uses Response.Write
to write the file (application/pdf) to the browser. I use the same method to render XLSX files to the browser as well. It works really great, but I need a callback or some event to tell the button when to stop spinning. This prevents the user from continuously clicking the Excel or PDF buttons. Does anyone know a way to detect the file dialog window when it was not created using JavaScript? I am also open to other methods of callback from the server side as well.
I have a jQuery plugin I use to dynamically create and render a form on a default.aspx asp page, then submit it. The page it gets submitted to is a pdf.aspx page. The page builds a PDF then uses Response.Write
to write the file (application/pdf) to the browser. I use the same method to render XLSX files to the browser as well. It works really great, but I need a callback or some event to tell the button when to stop spinning. This prevents the user from continuously clicking the Excel or PDF buttons. Does anyone know a way to detect the file dialog window when it was not created using JavaScript? I am also open to other methods of callback from the server side as well.
- See stackoverflow./questions/666468/… – Crescent Fresh Commented Jun 16, 2010 at 17:00
- That solution sounds great, but I am unclear as to the onload piece. Whether the iframe is loaded on page load, or dynamically created in JS, the onload happens before the form is even submitted. What am I missing? – Zacho Commented Jun 16, 2010 at 19:58
- possible duplicate of Detect when browser receives file download – Liam Commented Apr 24, 2014 at 9:05
1 Answer
Reset to default 5The way I do that was suggested in response to a question I asked here a while ago by T.J. Crowder. I can't find the response from the last time I wrote this up because the Stackoverflow "search" facility is so incredibly lame, so I'll probably type in a blog post. The basic idea is that your client code (Javascript) should append an extra parameter when it submits the request for the download. The parameter should contain some generated random string (probably just the current timestamp is good enough). The server then looks for that parameter, and when it's preparing the response with the download file it also sets a cookie and gives it that random value.
Right after the submit (or right before; it doesn't really matter), the Javascript code should start an interval timer with a routine to look at the value of document.cookie
and see if it contains that random string. As soon as the cookie does contain that string, then you know that the server has sent back its response and that the file download dialog has been presented.
本文标签: jqueryCan you use JavaScript to detect a file download window created server sideStack Overflow
版权声明:本文标题:jquery - Can you use JavaScript to detect a file download window created server side? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745481502a2660193.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论