I have a printUrl javascript/jquery function that loads a print friendly version of my web page into an iFrame and prints it. It seems to work in Chrome, Firefox, and IE but I can't get it to work in Microsoft Edge browser. The print dialog comes up but with the message "Nothing sent to print" in red. Any help would be appreciated. Function below:
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);
});
}