View Full Version : How to print the HTML of a component?

25 Mar 2012, 4:43 AM
ok i create my custom document viewer:

Ext.define('CustomDocumentViewer', { extend: 'Ext.Component',
html: ' some html webpage here',
style: { "background-color":"white", "overflow": "auto" }

And then i fill the HTML with some webpage.
And i want to print this HTML when user clicks a button, without opening new windows.
How to do this?

25 Mar 2012, 5:06 AM
No good way to do that, writing to a new document would be the best option.

25 Mar 2012, 6:28 AM
Ok, the new document is the last case scenario :)

I found something, but unfortunately it works only in FF and Chrome.

function printHTML(input){

var iframe = document.createElement("iframe"); // create the element
document.body.appendChild(iframe); // insert the element to the DOM

iframe.contentWindow.document.write(input); // write the HTML to be printed
iframe.contentWindow.print(); // print it
document.body.removeChild(iframe); // remove the iframe from the DOM


anybody has an idea how to modify this so it works everywhere?