我有以下打印功能
$scope.printDiv = function(divName) {
var printContents = document.getElementById(divName).innerHTML;
var popupWin = window.open('', '_blank', 'width=600,height=600');
popupWin.document.open()
popupWin.document.write('<html><head><link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" /><link rel="stylesheet" href="css/main.css"/></head><body onload="window.print()">' + printContents + '</html>');
popupWin.document.close();
}
我期待像网页一样的结果,但它没有正确对齐,特别是顶部菜单栏出现在打印的整个页面上。
最佳答案
您需要将新窗口的宽度
从600
增加到至少800
,例如,
// here I am using 1024 for proper alignment
var popupWin = window.open('', '_blank', 'width=1024,height=600');
关于javascript - 打印功能无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32708430/