0

I put an iframe for my all 100pages, and i want to add "Print" button to that iframe. So that every page has a button in it from iframe. But when click Print button only prints iframe page. I want to print whole seeing page.

<input type="button" value="Print" onclick="window.self.print();" />

or

<input type="button" value="Print" onclick="parent.window.focus();" />

I tried several codes but nothing works.

Manwal
  • 23,450
  • 12
  • 63
  • 93
Bbbb
  • 69
  • 2
  • 10

2 Answers2

2

Firstly you can add the function:

function printMe() {
  window.print()
}

And then from the button of the iframe you can call:

<input type="button" value="Print" onclick="printMe();" />

UPDATE

In the very same logic of @Manwal you can get the container by id or class and then focus on this. Example:

<input type="button" value="Print" onclick="document.getElementById('.container').focus();document.getElementById('.container').print();" />
Leonidas
  • 526
  • 11
  • 20
  • First of all, your goal is to accomplish the print. Why dont you take the print button from the iframe and put in the parent window? – Leonidas Jan 20 '15 at 08:15
  • I'm not able to edit parent windows, i can only make changes in iframe file. – Bbbb Jan 21 '15 at 10:39
0

Try this code:

<input type="button" value="Print" onclick="parent.window.focus();window.print();" />
Manwal
  • 23,450
  • 12
  • 63
  • 93