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);
          },

猜你喜欢

转载自www.cnblogs.com/mmy67/p/10044362.html
今日推荐