最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Unable to print an iframe on IE using JavaScript, prints parent page instead - Stack Overflow

programmeradmin4浏览0评论

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.

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.

Share Improve this question edited Jun 29, 2017 at 13:19 Alireza 105k27 gold badges277 silver badges173 bronze badges asked Jul 10, 2013 at 14:44 DebiprasadDebiprasad 6,17318 gold badges70 silver badges96 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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);
发布评论

评论列表(0)

  1. 暂无评论