GordonM GordonM - 1 year ago 78
CSS Question

Printing just an iFrame

I'm working on a case resolution system, and am currently using a jquery colorbox to display a list of open tasks to the user. Users want to be able to print this list, and I guess you can do it from within the page itself by adding a JavaScript link that triggers window.print from within the iframe. However, I've also got to account for users possibly selecting print from the browser's menu. In that case, if the colorbox is open, I just want to print its contents and not the overlying page.

Is it possible to hide everything except for the iframed content using a print media CSS file? If so, how can this be achieved? Failing that, I'll need to resort to JavaScript, so would achieving the effect in JavaScript be possible?

Answer Source

This could work if the iframe is a direct child of body

<style type="text/css" media="print">
   body *{display:none}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download