Using A Tracer Cookie To Watch For Browser Download-Prompts In Lucee CFML 5.3.6.61.

Yesterday, I was working on some report-generation for InVision that used Content-Disposition: attachment in order to prompt the user to save the generated content. My current approach is just to initiate the download in a new tab, which the browser automatically closes once the report has been generated. This approach is fine; but, it got me wondering if I could hook into the life-cycle of the report-generation and download-prompt programmatically. To do this, I wanted to explore the use of cookies in Lucee CFML 5.3.6.61.

First Attempt: Using an IFrame

My first attempt at hooking into the download-prompt was to try and route the report-generation through an iframe. The hope was that I could listen for the load event on the iframe itself, which would tell me when the user was prompted for the download.

Unfortunately, it doesn’t appear that the browser emits a load event on iframe elements that don’t render content.

Second Attempt: Nested IFrames

My second attempt was to nest one iframe element within another and then generate the report within the nested iframe. The hope here was that the outer iframe would have a load event since it generated content; but, that its load event would be tied to the loading of the inner iframe which was triggering the download.

This actually worked in modern browser (Chrome, Firefox, Safari). However, it did not work in IE11. And, since InVision still supports IE11, I had to find a solution that was more broadly supported.

**Third Attempt: Tracer Cookie and ****setInterval()**

My third attempt is based on an old jQuery plug-in by John Culviner. The idea behind this approach is that the report-generation code returns, as part of its HTTP Response, a Set-Cookie header that contains a unique tracer token. The client-side code can then start polling the document.cookie value for said unique token; and, when it shows up, we can be confident that the report-generation has been completed (and that the user has been prompted to download the binary).

#coldfusion #javascript / dhtml #browser download

Using A Tracer Cookie To Watch For Browser Download-Prompts In Lucee CFML 5.3.6.61
1.10 GEEK