Browser download complete event

后端 未结 6 1802
自闭症患者
自闭症患者 2020-12-15 21:33

We\'ve been looking for a while for an answer to this, but haven\'t found a solution.

We have a web server, which allows the user to download files (pdfs), which a

6条回答
  •  情歌与酒
    2020-12-15 22:21

    User cancelling can sometimes be detected in a servlet. Using Tomcat for example, try to stream a large file to the client, and then cancel the download. You can see the stacktrace of the exception in logs/catalona.out. I'm not sure, however, that this can be handled in servlet itself or a lower level (inside catalina).

    There is a preloading approach (sure with event listener facility) usually used to download images. It's up to the browser to download the whole PDF or not if it detects it as an unsupported image, but it worths giving a try. Here is an example.

    Another solution would be to implicitly download the PDF using or tags, and using their onload event listener. Not that this only works if an ActiveX or some sort of PDF file association is done in the browser, and probably won't work if user doesn't have a PDF viewer. Here is an example demonstrating this (see assisted solution: 11/21/04 08:22 AM, ID: 12638846).

    Mohsen

    提交回复
    热议问题