首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Microsoft Edge浏览器和打印

Microsoft Edge浏览器和打印
EN

Stack Overflow用户
提问于 2015-08-24 21:21:24
回答 2查看 3.9K关注 0票数 2

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

代码语言:javascript
复制
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);
});
}

EN

回答 2

Stack Overflow用户

发布于 2015-09-15 21:37:14

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

票数 1
EN

Stack Overflow用户

发布于 2016-09-30 19:22:31

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

代码语言:javascript
复制
parent.document.getElementsByName("pdfjs-frame")[0].contentWindow.document.execCommand("print", false, null);

posted here on StackOverflow

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32183416

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档