打印功能不能正常工作

Print function not working properly

本文关键字:工作 常工作 功能 能不能 打印      更新时间:2023-09-26

我有以下打印函数

$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();
 }

我期待的结果就像每一个网页,但它没有正确对齐,特别是顶部菜单栏出现在整个页面的打印。

您需要将新窗口的width600增加到至少800,如

// here I am using 1024 for proper alignment
var popupWin = window.open('', '_blank', 'width=1024,height=600');