Can someone please help me out with printing the contents of an IFrame via a javascript call in Safari/Chrome.
This works in firefox:
$('#' + id)[0].focus();
$('#' + id)[0].contentWindow.print();
this works in IE:
window.frames[id].focus();
window.frames[id].print();
But I can't get anything to work in Safari/Chrome.
Thanks
Andrew
I had to make few modifications in order to make it with in IE8 (didn't test with other IE flavours)
1) document.frames[param] seem to accept a number, not ID
2) I had a print dialog displayed upon page load and also there was a link to "Click here to start printing" (if it didn't start automatically). In order to get it work I had to add focus() call
You can also use
or
Use firefox
window.frames
but also add thename
property because that uses the iframe in firefoxIE:
Firefox:
Put a print function in the iframe and call it from the parent.
iframe:
parent:
here is my complete, cross browser solution:
in the iframe page:
in the main page
Update: Many people seem to be having problems with this in versions of IE released since I had this problem. I dont have time to-reinvestigate right now, if youre stuck i suggest you read all the comments in this whole thread!
The 'framePartsList.contentWindow.print();' was not working in IE 11 ver11.0.43
Therefore I have used framePartsList.contentWindow.document.execCommand('print', false, null);