首页 > Web开发 > 详细

js生成txt文件

时间:2015-01-21 13:08:49      阅读:279      评论:0      收藏:0      [点我收藏+]
                

          var _txt = ‘这只是一个测试文本‘;
          var isIE = (navigator.userAgent.indexOf(‘MSIE‘) >= 0); if (isIE) { var strHTML = _txt; var winSave = window.open(); winSave.document.open("text","utf-8"); winSave.document.write(strHTML); winSave.document.execCommand("SaveAs",true,"code.txt"); winSave.close(); } else { var elHtml = _txt; var mimeType = ‘text/plain‘; $(‘#createInvoteBtn‘)[0].setAttribute(‘download‘, ‘code.txt‘); $(‘#createInvoteBtn‘)[0].setAttribute(‘href‘, ‘data:‘ + mimeType + ‘;charset=utf-8,‘ + encodeURIComponent(elHtml)); }

 由于IE跟火狐不兼容第二种方式,故写了两种!

js生成txt文件

原文:http://www.cnblogs.com/307914070/p/4238450.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!