Ben Nadel explores the idea of using tracer cookies to monitor and respond to download-prompts using Lucee CFML 22.214.171.124. In this demo, he shows an overlay while a report is being generated; and then, closes the overlay when the user is prompted to download the report.
Yesterday, I was working on some report-generation for InVision that used
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.
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.
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).