Access denied for iframe printout in Firefox

0

I have a system where I need to print a PDF when I click the button.

The url is constructed according to the shipping ID, so dynamically, I use an iframe that will load the data, and when loaded, I call a function to print what is in iframe .

I'm doing this:

$scope.imprimir = function imprimir (protocolo_id) {

    if (imprimir.carregando) return;

    var url_protocolo = '/protocolos/imprimir/' + protocolo_id;

    imprimir.carregando = true;

    angular.element('#imprimir_protocolo').attr('src', url_protocolo).on('load', function () {

        var frame = $window.frames['imprimir_protocolo'];

        frame.focus();

        frame.print();


        delete imprimir.carregando;

        $scope.$apply();
    })
}

In the line where I am calling frame.focus() , when I use Firefox, the following error is appearing:

  

Permission denied to access property "print"

    
asked by anonymous 20.02.2017 / 14:19

1 answer

1

You can not run some scripts in an iframe directly, you can try to use contentWindow :

var cw = frame.contentWindow;
cw.focus();
cw.print();

If you are in different domains or different protocols maybe not accessible yet, then you can try to inject a function inside the iframe, something like:

<script>
function printPage() {
    window.focus();
    window.print();
}
</script>

And call:

frame.contentWindow.printPage();

I have not worked for some time, but I remember that every browser had a behavior and it varied a lot.

    
20.02.2017 / 14:29