Is there an alternative method to window.print ()?

1

I want to print an iframe, but the print () method does not work because my src attribute contains

  

Is there a method that allows me to call the browser print window?

Update: Here is the error:

  

Uncaught SecurityError: Blocked a frame with origin   " link " from accessing a frame with origin "null". The   frame requesting access has a protocol of "http", the frame being   accessed has a protocol of "data". Protocols must match.

my iframe:

 {
     xtype      : "component",
     hidden: true,
     id         : 'iframeDudu',
     items:[
         //framedudu
     ],

  autoEl     : {
    width : 1000,
    //hidden: true,
    height: 700,
    tag   : "iframe",
    //items: myPanel
    id:'frameAutoEl',
    //src   : "http://testeecm:8080/webdesk"

    //src   : "http://servidorweb/redmine/login?back_url=http%3A%2F%2Fservidorweb%2Fredmine%2F"
    //Uncaught SecurityError: Blocked a frame with origin "http://testeecm:8080" from accessing a
    // frame with origin "http://servidorweb". Protocols, domains, and ports must match.

    //html           : '<iframe src="http://forum.extjs.com.br/index.php?/topic/27562-resolvido-n%C3%A3o-est%C3%A1-exibindo-arquivo-pdf-na-window-do-extjs/?hl=imprimir"></iframe>',//html:thtml//acontecenada//src:'data:text/html;charset=utf-8,'+encodeURI(thtml)src:"data:text/html;charset=utf-8,%3Chtml%3E%3Cbody%3Efoo%3C/body%3E%3C/html%3E",
    // Uncaught SecurityError: Blocked a frame with origin "http://testeecm:8080" from accessing a frame
    // with origin "null".  The frame requesting access has a protocol of "http",
    // the frame being accessed has a protocol of "data". Protocols must match.

     }// final autoElement


}
    
asked by anonymous 04.12.2015 / 19:19

3 answers

0

I did not find another method that printed an iframe. The alternative was to create a window and pass the html content to it. I used the Handlebars library to pass the data to the html window. So, I do not need to print the iframe, nor do I need the src property of the iframe. I only print window with content html already embedded previously:

var imprimirAso = function (){
source = '<button id="imprimir" onclick="divPrint()">Imprimir</button>' +
'<table>' +
'<tr>' +
'<td style="width:100px">' +
'<img class="logo"/>' +
'</td>' +
'</td>' +
'<td><strong>Empresa:</strong> {{razaoSocial}}</td>' +
'<td><strong>CNPJ:</strong>    {{cnpj}}</td>' +
'</td>'',

var template = Handlebars.compile(source);

var data = { "razaoSocial": razaoSocial, "cnpj": cnpj, "endereco": endereco, "cidade": cidade, "estado": estado,
"fantasiaClinica"       : fantasiaClinica, "enderecoClinica": enderecoClinica, "bairroClinica": bairroClinica,
"cidadeClinica"         : cidadeClinica, "ufClinica": ufClinica, "cepClinica": cepClinica, "telefoneClinica": '',
"nomeCandidato"         : Ext.getCmp('nome').getValue(), "descSetor": Ext.getCmp('descSetor').getValue(),
"dataNascimento"        : Ext.get('dataNascimento').dom.value, "cpf": Ext.getCmp('cpf').getValue(),
"funcao"                : Ext.getCmp('funcao').getValue(),
"example"               : "<button> Hello </button>"
},

var result = template(data);
wnd = window.open('', '', 'width=1000,height=850');
wnd.document.write(result);
}
    
15.12.2015 / 12:16
0

Try this solution:

window.frames["printf"].focus();
window.frames["printf"].print();

But with the source code it is easier to identify the problem.

    
04.12.2015 / 19:24
0

An alternative:

JS

function printFrameContent(id) {
    var cFrame = document.getElementById(id).contentWindow;
    cFrame.focus();
    cFrame.print();
    return false;
}

HTML

<iframe id="conteudo" src=""></iframe>

<button onclick="printFrameContent('conteudo')"> Teste de Impressão </button>
    
04.12.2015 / 19:27