Search code examples
javascriptiframewebkitprinting

How do I print an IFrame from javascript in Safari/Chrome


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


Solution

  • Put a print function in the iframe and call it from the parent.

    iframe:

    function printMe() {
      window.print()
    }
    

    parent:

    document.frame1.printMe()