0

I have an angular directive that uses an iframe to download a file. I want to be able to detect when that iframe is loaded, but the event isn't firing.

        var iframe = angular.element('<iframe></iframe>');
        iframe.on("load", function() { console.log("loaded"); });
        iframe.attr('src', url);
        iframe.css('display', 'none');

        angular.element(document.body).append(iframe);
Smeegs
  • 9,151
  • 5
  • 42
  • 78
  • Maybe take a look at this answer: http://stackoverflow.com/a/23948165/1887101 – Adjit May 24 '16 at 16:45
  • Thanks, but that's not the same question. – Smeegs May 24 '16 at 16:50
  • Your code works for me [Plunker](http://plnkr.co/edit/YVc8O07Q8OZ33Bsdkv7b). Make sure URL is correct and doesn't refuse to be loaded in an iframe – Kirill Slatin May 24 '16 at 16:52
  • Hmmm, that might be the key. The url is working. But like I mentioned, it's to download a file. Specifically an excel file. So the content type and disposition may be playing games with the event handler. – Smeegs May 24 '16 at 16:53
  • Do you have a URL to such a file that you can share without security threat? In this case update the plunker to create an MCVE – Kirill Slatin May 24 '16 at 16:54
  • Hmmm, nope. But let me see if I can find a comparable link online. – Smeegs May 24 '16 at 16:56
  • I think with AngularJS you should engage different approaches, for example [simple anchor](http://stackoverflow.com/questions/16670754/angularjs-simple-file-download) – Kirill Slatin May 24 '16 at 18:41

0 Answers0