1. 程式人生 > >html列印後不重新整理當前頁

html列印後不重新整理當前頁

這種方法可以在列印的頁面中新增樣式,新頁面跳轉列印

 doPrint(ids){
            var titleHTML=document.getElementById(ids).innerHTML;
            var OpenWindow = window.open("");
            OpenWindow.document.write('<!DOCTYPE html><html lang="zh-cn">');
            OpenWindow.document.write("<head>");
            OpenWindow.document.write(
'<meta charset="utf-8">'); OpenWindow.document.write('<title></title>'); OpenWindow.document.write('<style>.table{width: 100%;font-size:13px;}</style>'); OpenWindow.document.write('</head>'); OpenWindow.document.write('<body><div class="layout-g-content" id="p">
'); OpenWindow.document.write('</div></body>'); OpenWindow.document.write('</html>'); OpenWindow.document.getElementById("p").innerHTML= titleHTML; window.setTimeout(function(){ OpenWindow.print(); OpenWindow.close(); },
500); },