web页面自动保存本页面的内容到本地

web页面自动保存本页面的内容到本地的实现代码:
 
<script language="javascript" type="text/javascript">
         //保存聊天记录到本地 
         function save_record() {
             //取得当前日期作为文件名 
             var time = new Date();
             var filename = time.toLocaleDateString();
 
             //获取当前页面部分内容 -------此处可以加深理解DOM树的节点模型
             var record = document.documentElement. innerHTML ;
 
             //打开新窗口保存 
             var winRecord = window.open('about:blank', '_blank', 'top=0');
             winRecord.document.open("text/html", "utf-8");
             winRecord.document.write(record);
             winRecord.document.execCommand("SaveAs", true, filename + "试卷分析报告" + ".htm");
             winRecord.close();
         } 
 
    </script>
 
 
在要点击保存的地方应用save_record()函数即可
原文地址:https://www.cnblogs.com/xiaopanlyu/p/2950840.html