1

I have a website where users can download a formatted PDF document or Excel file of records. To do this without a postback I programmatically create an iframe and set the source to a URL containing an id and a key to identify the data required. A spinner is displayed to indicate that a download is under way. Once the data has been processed by the ASP.NET handler and the iframe receives the results, the onload event is 'supposed' to hide the spinner.

showSpinner();
var i = document.createElement("iframe");
var id = 2;
var key = '1234567890abcd';
var fileType = 'pdf';
i.src = 'Download.ashx?Type=' + fileType + '&ID=' + id + '&Key=' + key;
$(i).on("load", function () { hideSpinner(); })
i.style.display = "none";
document.body.appendChild(i);

I have also tried adding the onload event without jQuery or addEventListener by embedding it directly in the iframe markup using

i.setAttribute("onload", "hideSpinner();");

Both of these approaches work fine in Firefox and Chrome, but IE and Edge don't fire the onload event in either case. I have searched and found lots of people reporting problems along similar lines. Despite trying several suggestions, it seems that IE just doesn't like this sort of thing.

As jQuery has deprecated browser detection and UserAgent sniffing is frowned upon, is there a more 'acceptable' way of disabling the spinner using feature detection, without me just using

if (/trident/i.test(navigator.userAgent)) hideSpinner();

Alternatively, and to be honest, preferably, any suggestions on how to solve the iframe problem would be gratefully received.

YDdraigLas
  • 11
  • 1
  • did you try this http://stackoverflow.com/questions/25121384/ie-download-file? – Zamboney Mar 29 '16 at 12:18
  • I hadn't seen that, but unless I'm missing something I'm not sure that it achieves anything beyond what is already happening. The file downloads successfully in IE; it's just the iframe load event that isn't being triggered once the data is ready. – YDdraigLas Mar 29 '16 at 12:33

0 Answers0