繁体   English   中英

无法使用JavaScript在IE上打印iframe,而是打印父页面

[英]Unable to print an iframe on IE using JavaScript, prints parent page instead

我有以下JavaScript代码:

$(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();
        });
    });
});

它适用于Chrome和Firefox。 但是当我点击IE上的按钮时,它会打印父页面,而不是打印iframe。

我一直在寻找在Internet Explorer中打印Iframe的解决方案。 经过数小时的搜索,我得到了解决方案。 它对我有用。 请检查以下链接

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

document.execCommand('print', false, null);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM