js保存当前网页HTML到本地(Chrom Firefox)
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>网页HTML存本地</title> <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script> </head> <body> <a href="#">保存文件</a> <script> function fake_click(obj) { var ev = document.createEvent("MouseEvents"); ev.initMouseEvent( "click", true, false, window, 0, 0, 0, 0, 0 , false, false, false, false, 0, null ); obj.dispatchEvent(ev); } function export_raw(name, data) { var urlObject = window.URL || window.webkitURL || window; var export_blob = new Blob([data]); var save_link = document.createElementNS("http://www.w3.org/1999/xhtml", "a") save_link.href = urlObject.createObjectURL(export_blob); save_link.download = name; fake_click(save_link); } var test=document.getElementsByTagName(‘html‘)[0].outerHTML; console.log(test); $(‘a‘).click(function() { export_raw(‘test.html‘, test); }); </script> </body> </html>
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。