-1

I created the following function to resize the height of an iframe element always to 100% after load:

app.directive('iframeAutoSize', [function() {
    return {
        restrict: 'A',
        link: function(scope, element, attrs) {
            element.on('load', function() {
                console.log(element[0]);
                var iFrameHeight = element[0].contentWindow.document.body.scrollHeight + 'px';
                element.css('height', iFrameHeight);
            });
        }
}}]);

usage:

<iframe iframe-auto-size src="..." />

Problem: I'm getting the following error when launching it:

Error: Permission denied to access property "document".

Obviously it's not allowed to execute window.document on the iframe element. But how could I else find out the height?

I'd prefer a plain angular/js solution without jquery.

membersound
  • 81,582
  • 193
  • 585
  • 1,120

1 Answers1

2

this isn't a AngularJS Error, this is a SOP Error, the iFrame is probably sandboxed!

The iFrame comes from a different domain??

Community
  • 1
  • 1
Hitmands
  • 13,491
  • 4
  • 34
  • 69
  • Yes the content to be embedded into the iframe comes from a different domain. Is it possible to overcome this error? – membersound Oct 26 '15 at 11:48
  • You maybe not consider this as error, this is how the SOP works! You can't do anything with this content because isn't a your content! Read the link I posted before, but i don't think that you'll find any workaround! It's security :) – Hitmands Oct 26 '15 at 11:53