Ivo
Ivo

Reputation: 363

Print the iframe content

I want to print the content of the iframe. I viewd several examples but non of them helped me for my case. I have the following piece of code

<div id="print-area">
    <iframe src='data:text/html;charset=utf-8,<?php echo $content ?>'></iframe>
</div>

And when the #print button is clicked: (this code prints out the content of the div #print-area)

$("#print").click(function (e) {
        var newWindow = window.open();
        newWindow.document.write($('#print-area').html());
        newWindow.print()
    });

The code works and print window is prompted, but when I try to put content of the iframe in the document.write(...) the function does not work. Any idea?

tried solutions:

Print iFrame content using Javascript

How to Print iframe content

and from other topics, but did not manage to print my iframe content

Upvotes: 0

Views: 952

Answers (1)

Rajiv
Rajiv

Reputation: 78

use

<iframe id="abcd" src='data:text/html;charset=utf-8,<?php echo "someHtmlContent" ?>'>


            </iframe>
var newWindow = window.open();
                newWindow.document.write($('#abcd').contents().find("html").html());
                newWindow.print()

because iframe is a independent page it not access by windows class that why use parent class

Upvotes: 1

Related Questions