android - window.print div 元素在 android chrome 上显示整个页面(在 win 10 chrome 上打印 div 部分)
问题描述
我正在尝试在 android chrome 上打印 div 内的文本这适用于 windows 10 chrome 但在 android chrome 上,它会打印,但会显示带有标题和打印按钮的整个页面。
任何帮助表示赞赏
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function printDiv(divName){
var printContents = document.getElementById(divName).innerHTML;
var originalContents = document.body.innerHTML;
docunt.body.innerHTML = printContents;
window.print();
document.body.innerHTML = originalContents;
}
</script>
</head>
<h2> Test print </h2>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<body>
<div id="PrintMe" >
<p>
I'm trying to print the text inside the div on android chrome<br>
This works on windows 10 chrome <br>
but on android chrome, it prints, but shows the whole page<br>
with header and print button.
</p>
</div>
<button id="print" onclick= "printDiv('PrintMe')" > Print </button>
</body>
</html>
解决方案
推荐阅读
- r - 如何在一个时间窗口中找到多个变量的同步增加?
- sql - 使用 JPA、spring 和 kotlin Map 保存的 json 数据的正确值
- python - 用 0 替换缺失值
- generics - Fortran 中的模板
- jakarta-ee - 在 OpenLiberty 中为 Arquillian 测试配置默认 JMS 连接工厂和队列
- reactjs - 为什么扩展运算符从 useEffect() 中的承诺返回一个空数组?
- javascript - 如何使用 axios 在 Vue 应用程序中获取、更新和渲染数据?
- python - 数组中的 Django 项目不显示
- date - 在 Power BI 中对 2 个表使用 3 个日期字段
- javascript - 出现错误“无法读取 null 的属性‘push’”