1

I want to print iFrame content using javascript. I've tried to following but it only works in Chrome.

window.frames[frameid].print();

and

var iframe = document.getElementById("iframeID").contentWindow;
iframe.focus();
iframe.print();

It is not working on Mozilla Firefox.

I'm showing PDF in iFrame on a page.

Alok Patel
  • 7,842
  • 5
  • 31
  • 47

2 Answers2

1

Just use onload="window.print();" in the body tag of the iframe code.

Or you could simply use:

<script>window.print();</script>

Anywhere in the source code of the iframe.

It also appears you've made a typo. Replace ifrmae with iframe.

kjdion84
  • 9,552
  • 8
  • 60
  • 87
  • As I've mentioned I'm loading PDF file directly in the iframe, so I don't know where I can add window.print() function. – Alok Patel Jan 11 '16 at 09:06
0

.contentWindow.print(); worked for me.

I've opened the PDF in iframe of fancybox and then called .contentWindow.print();.

Though it's not supported in some older browsers.

Alok Patel
  • 7,842
  • 5
  • 31
  • 47