将html页面作为doc文档下载到本地,也可以用于下载生成页面下载
//1.获取文本 let topDiff =-1; let content=""; var filename= document.getElementsByClassName('doc-title')[0].innerText; const target = document.querySelectorAll(".reader-word-layer"); target.forEach(x=>{ if (x.style.top !== topDiff){ content +="\n" topDiff = x.style.top; } content += x.innerText; }); //2.创建下载链接,下载到本地 var element = document.createElement('a'); element.setAttribute( 'href','data:text/plain;charset-utf-8,'+encodeURIComponent(content)); element.setAttribute( 'download', filename+".doc"); element.style.display=".reader-word-layer"; document.body.appendChild(element); element.click(); document.body.removeChild(element);
不做解释了,都是很简单的toy代码
上一篇:http协议
下一篇:没有了!