0

I have a URL which onclick it downloads a file. Some of these files are quite big and it takes some time for the browser to receive it. This can be frustrating for the user, especially for the inexperienced ones, who don't realize that the file is about to be downloaded.

I tried to add the tag "download" in the element but it doesn't work for my Chrome, Firefox version. As an alternative I added:

target = "_blank"

Which opens a new blank page and once the download starts it closes it. But this solution is not very elegant.

Is there a way to track when the browser will receive the file? So I am able to show an indicator?

user1919
  • 3,818
  • 17
  • 62
  • 97
  • Similar SO can be found here - http://stackoverflow.com/questions/1106377/detect-when-browser-receives-file-download – Nikhil Nanjappa May 09 '17 at 09:00
  • @Nikhil Nanjappa this questiona and answer is based on sending a post request via a submit. In my case there is no ajax request. Its just a url with a onclick function attached to it. – user1919 May 09 '17 at 09:31
  • where are the files you are downloading from? a server i presume. When you say receive the file, you mean receive the file from a server right – Nikhil Nanjappa May 09 '17 at 09:32
  • Well its a bit more complicated. A request (url) is made to "geoserver", who handles the delivery of the file. Actually geoserver is connected with a postgres db and takes care of delivering the file in the specific format. – user1919 May 09 '17 at 09:45
  • Well that's it then, you(being the client/browser) need not worry about what is happening server side to get the file. As long as it made any form of request, you can use that to track and show corresponding message to the user. There is no other possible way to track the files without the request itself – Nikhil Nanjappa May 09 '17 at 09:48
  • Can you show the code how you are making the request to the geoserver to fetch the file. That's the important part. – Nikhil Nanjappa May 09 '17 at 09:50
  • Hmmm. The request is just a URL like this: http://main_domain?format_options=charset%3AUTF-8&typename=sdn_bnd_admin1_a_gov_1&outputFormat=SHAPE-ZIP&version=1.0.0&service=WFS&request=GetFeature Its a specific request, which Geoserver can handle and return the specific data in the predefined output format. – user1919 May 09 '17 at 09:58
  • 1
    Hmm I was expecting you to have an api call like this .. http://geoserver.geo-solutions.it/edu/en/rest/js_rest_examples.html. Do you have any "rest-example.js" or init() in your project – Nikhil Nanjappa May 09 '17 at 10:17

0 Answers0