有些在住房置业融资担保业务系统写过的代码在将来的不久还是可以用到,我之前有写过截取部分网页内容并进行打印,贴出打印函数
export const printHtml=()=>{
const html_back = window.document.body.innerHTML;
const start = "<startprint>";
const end = "</startprint>";
let html = html_back.substr(html_back.indexOf(start) + 12);
html = html.substring(0, html.indexOf(end));
const newWin=window.open("");
let cssstr='';
const arr=window.document.getElementsByTagName("link");
arr.forEach(item=>{
const href=item.getAttribute("href");
if(href.includes('umi')){
cssstr=href;
return ;
}
});
console.log(cssstr)
newWin.document.write(<!DOCTYPE html> <html lang="en"> <head> <meta content="text/html; charset=UTF-8" > <title></title> <link rel="stylesheet" href=${cssstr} /> </head> <body> <div id="root"></div> </body> </html>
);
setTimeout(item=>{
newWin.document.body.innerHTML = html;
newWin.print();},500);
};
网友评论