This is my code
<script> var body = "dddddd" var script = "<script>window.print();</scr'+'ipt>"; var newWin = $("#printf")[0].contentWindow.document; newWin.open(); newWin.close(); $("body",newWin).append(body+script); </script> <iframe id="printf"></iframe>
This works but it prints the parent page, how do I get it to print just the iframe?
document. getElementById("print-iframe"). contentWindow. print();
JavaScript does not have any print object or print methods. You cannot access output devices from JavaScript. The only exception is that you can call the window.print() method in the browser to print the content of the current window.
I would not expect that to work
try instead
window.frames["printf"].focus(); window.frames["printf"].print();
and use
<iframe id="printf" name="printf"></iframe>
Alternatively try good old
var newWin = window.frames["printf"]; newWin.document.write('<body onload="window.print()">dddd</body>'); newWin.document.close();
if jQuery cannot hack it
Live Demo
document.getElementById("printf").contentWindow.print();
Same origin policy applies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With