【发布时间】:2020-05-26 07:34:55
【问题描述】:
我正在尝试使用window.print() 打印新打开的窗口。
我的问题是,只有页面的 start 部分正在打印(只有当您滚动到窗口左上角时看到的内容)。
这是我的代码:
var printWindow = window.open("", "Print", "width=" + nWidth + "px, height=" + nHeight+ "px");
printWindow.document.write(sSvgData, sDivData);
printWindow.document.close();
printWindow.print();
我已经尝试过的解决方案,但对我不起作用:
1) 将整个 html 写入文档(使用window.document.write())并在标题中包含我的css
<html><head><link rel="stylesheet" href="../css/style.css" type="text/css" media="print"/></head>
<body>...
style.css:
@media print {
body, html, div, #wrapper {
height: 100%;
width: 100%;
}
}
2) 与 1) 相同,但包括内联样式:
<html><style>@media print { body, html, #wrapper { height: 100%; width: 100%;} }</style><body>...
【问题讨论】:
标签: javascript jquery window