我有一个printUrl javascript/jquery函数,可以将我的网页的打印友好版本加载到iFrame中并打印出来。它似乎可以在Chrome、Firefox和IE中工作,但我无法让它在Microsoft Edge浏览器中工作。打印对话框出现,但显示红色的消息"Nothing sent to print“。任何帮助都将不胜感激。下面的函数:
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);
});
}
发布于 2015-09-15 21:37:14
这是一个问题,已经在MS Connect网站[Edge] Printing iframe window ends up printing top window上发布了
发布于 2016-09-30 19:22:31
我们找到了这个解决方案:
parent.document.getElementsByName("pdfjs-frame")[0].contentWindow.document.execCommand("print", false, null);https://stackoverflow.com/questions/32183416
复制相似问题