10

I have the following JavaScript code:

$(document).ready(function() {
    $('a#print_button').click(function(event) {
        event.preventDefault();

        var print_url = 'print.html';

        if ($('#print_page').length == 0) {
            $("body").append('<iframe id="print_page" name="print_page" src=' + print_url + ' style="display: none; @media print { display: block; }"></iframe>');
        } else {
            $('#print_page').attr("src", print_quote_url);
        }

        $('#print_page').on("load", function() {
            frames["print_page"].focus();
            frames["print_page"].print();
        });
    });
});

It works on Chrome and Firefox. But when I click on the button on IE, it prints the parent page, instead of printing the iframe.

Alireza
  • 100,211
  • 27
  • 269
  • 172
Debiprasad
  • 5,895
  • 16
  • 67
  • 95

1 Answers1

19

I was looking for a solution to print Iframes in Internet Explorer. After hours of search i got the solution. it worked for me. Please check the following link

http://bytes.com/topic/misc/answers/629926-ie7-printing-iframe-solution

document.execCommand('print', false, null);
sriram
  • 191
  • 1
  • 4
  • 3
    Welcome to Stack Overflow! While this may theoretically answer the question, [it would be preferable](http://meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Bill the Lizard Oct 23 '13 at 11:09
  • Thanks a lot . I have also spend many hours for finding it's solution for IE8 and it worked for me. – SeeTheC Jul 08 '14 at 08:20
  • This does not seem to work in Firefox though. So it is better to check the browser vendor first and then only use this one for IE. – Holger Jul 05 '17 at 09:20