【问题标题】:Microsoft Edge Browser and PrintingMicrosoft Edge 浏览器和打印
【发布时间】:2015-08-24 13:21:23
【问题描述】:

我有一个 printUrl javascript/jquery 函数,可以将我的网页的打印友好版本加载到 iFrame 中并打印出来。它似乎在 Chrome、Firefox 和 IE 中工作,但我无法在 Microsoft Edge 浏览器中工作。打印对话框出现,但消息“没有发送到打印”为红色。任何帮助,将不胜感激。函数如下:

function printUrl(url) {
$('body').append('<iframe width="1" height="1" id="printFrame" style="display: none; @media print { display: block; }"/>');
$('#printFrame').attr('src', url);
$('#printFrame').load(function() {
    var ua = window.navigator.userAgent;
    var msie = ua.indexOf("Trident"); // detect if IE

    if (msie > 0) {

        var target = document.getElementById('printFrame');
        try {
            target.contentWindow.document.execCommand('print', false, null);
        } catch (e) {
            target.contentWindow.print();
        }
    } else {
        // this code executes for Edge printing as well as Chrome, Firefox  
        var frame = document.getElementById('printFrame');
        if (!frame) {
            $.alert("Error: Can't find printing frame.");
            return;
        }
        frame = frame.contentWindow;
        frame.focus();
        frame.print();
    }
    setTimeout(function() {
        $('#printFrame').remove()
    }, 500);
});
}

【问题讨论】:

    标签: javascript jquery printing microsoft-edge


    【解决方案1】:

    这是一个问题,已经发布在 MS Connect 网站[Edge] Printing iframe window ends up printing top window

    【讨论】:

      【解决方案2】:

      我们找到了这个解决方案:

      parent.document.getElementsByName("pdfjs-frame")[0].contentWindow.document.execCommand("print", false, null);
      

      posted here on StackOverflow

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-26
        • 2020-05-03
        • 2015-09-13
        • 2016-04-20
        • 1970-01-01
        相关资源
        最近更新 更多