We can detect iFrame source change with onload event. I tried to create iFrame onLoad event with directive, but that is not working. So here I am sharing the solution which is working. Real height of the iFrame document can be detected by iFrameID.contentWindow.document.body.scrollHeight

Calling AngularJS function from javascript 

JavaScript onload event for iframe works good. Here we are going to call AngularJS function from javascript function. To call AngularJS function, we need to get scope of the element. 
var ifrm = document.getElementById('myIframe');
angular.element(ifrm).scope().onIframeLoad(ifrm);

Script

$scope.onIframeLoad = function(iFrameID) {
    if (iFrameID) {
        // here you can make the height, I delete it first, then I make it again
        iFrameID.height = "";
        iFrameID.height = iFrameID.contentWindow.document.body.scrollHeight+ "px";
    }
};

0 comments:

Blogroll

Follow this blog by Email

Popular Posts