首页 > 解决方案 > 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>

标签: androidhtmlgoogle-chrome

解决方案


推荐阅读