The last method mentioned in the accepted answer, as a result, looks like this:
iframe = document.getElementById('iframe-id'); var printed = iframe.contentWindow.document.execCommand('print', false, null); if (!printed) window.print();
alternative:
try { iframe = document.getElementById('iframe-id'); iframe.contentWindow.document.execCommand('print', false, null); } catch(e) { window.print(); }
similar method used by printThis
if (document.queryCommandSupported("print")) { $iframe[0].contentWindow.print(); $iframe[0].contentWindow.document.execCommand("print", false, null); } else { $iframe[0].contentWindow.focus(); $iframe[0].contentWindow.print(); }
Kyle baker
source share