javascript - Get onload event of an angular.element iframe -
i trying onload event on added iframe. happens inside service function call. supposed download file, works fine. need wait until iframe loaded return promise resolve. reduced code problem is:
iframe = angular.element('<iframe id="blaba" style=\'position:fixed;display:none;top:-1px;left:-1px;\'/>') angular.element(document.body).append iframe # onload bind here iframe.attr('src', url)
i tried
iframe.onload = -> $log.info 'iframe loaded'
also
iframe.on 'load', (event) -> $log.info 'iframe loaded'
i tried select iframe via id , bind load event on that. doesn't work. ideas or suggestions?
best regards
try
app.controller('mainctrl', () => { var iframe = angular.element('<iframe id="blaba" height="200"/>') angular.element(document.body).append(iframe); // onload bind here var url = 'test.txt'; iframe.attr('src', url); iframe.on('load', event => console.log('iframe loaded')) });
plunker: https://plnkr.co/edit/xeaycmg6l6ng2t1zacfn?p=preview
Comments
Post a Comment