Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread TBrowser - onLoad Event
Thu, Mar 23 2017 12:48 PMPermanent Link

Andrew Oborn

Hi,

In EWB2 we're using a THTMLForm & TBrowser to perform a http post for a file upload.
While it's uploading, as it may take a few moments for the server to send a response, I'm popping up a "please wait" form with a nice animated graphic so the user can see something is happening.

If the server response is then normal html, the TBrowser.OnLoad event fires, so I can hide the wait form from here and user continues working.

However, for some, we need the server to return a CSV file as the response, sending relevant headers
e.g.
Content-Type: text/csv; charset=utf-8
Content-Disposition: attachment; filename="xxxxxxxxxx.csv"
.... which the browser then treats as a file download (which is fine)... but this means the TBrowser.OnLoad event doesn't appear to fire.  I've re-created by simplifying to a http "get" on a csv file with the THTMLForm, and having the TBrowser.OnLoad event update a label with current time.

I'm guessing its the browser/javascript engine not firing an event (rather than an EWB issue) which is understandable as its not something happening within the page html..... has anyone seen this / found any workarounds so we can remove a "please wait" dialog if its a file download response?

Thanks
Thu, Mar 23 2017 1:40 PMPermanent Link

Matthew Jones

Andrew Oborn wrote:

> guessing its the browser/javascript engine not firing an event

I'd agree. Go search normal JavaScript solutions. My first thought would be to have the server return an auto-refresh page to fetch the CSV, so the trigger happens, and so does the download. Maybe not so easy though.

In my shop I poll for a status of order processing, and the response can be a simple status (number and message) or a redirect to tell the browser to go somewhere else. Depending on how much control you have, that might be an option, allowing you to control with more precision.

--

Matthew Jones
Thu, Mar 23 2017 2:03 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Andrew,

<< I'm guessing its the browser/javascript engine not firing an event (rather than an EWB issue) which is understandable as its not something happening within the page html..... has anyone seen this / found any workarounds so we can remove a "please wait" dialog if its a file download response? >>

Yeah, the browser won't fire an OnLoad for a file download.  If you *know* that you're going to be downloading a file, then the suggestion mentioned here is a good idea:

http://stackoverflow.com/questions/16086162/handle-file-download-from-ajax-post

(the one starting with "Setting headers server-side")

Namely, use a TServerRequest (AJAX) to initiate the download and have the server response with the URL for the download.  Then, use a hidden TBrowser (iframe) to navigate to the download URL.

Tim Young
Elevate Software
www.elevatesoft.com
Image