IE浏览器下用JS创建文件
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了IE浏览器下用JS创建文件,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1904字,纯文字阅读大概需要3分钟。
内容图文
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > < html xmlns ="http://www.w3.org/1999/xhtml" > < head > < meta http-equiv ="Content-Type" content ="text/html; charset=gb2312" /> < title >IE浏览器下用JS创建文件</title><script type="text/javascript">function logInfo(title,text){ var fso, tf; var folderPath="D:\\jslog"; var logFileName="D:\\jslog\\"+getDateStr()+".txt"; //20150922.txt fso =new ActiveXObject("Scripting.FileSystemObject");//获取对象if(!checkFolderExists(fso,folderPath)){//判断是否存在该日志文件夹,不存在就创建 fso.CreateFolder(folderPath);//创建 } if(checkFileExists(fso,logFileName)){ tf = fso.OpenTextFile(logFileName, 8, true); }else{ tf = fso.CreateTextFile(logFileName, true);//创建一个文件 } // 写一行,并且带有新行字符。 tf.WriteLine(title); tf.WriteLine(getDateStr("DateTime")+text); tf.WriteLine(); tf.Close();//关闭 } //检查文件夹是否存在,是true否falsefunction checkFolderExists(fso,folderPath){ if(fso.FolderExists(folderPath)){ returntrue; }else{ returnfalse; } } //检查文件是否存在,是true否falsefunction checkFileExists(fso,filePath){ if(fso.FileExists(filePath)){ returntrue; }else{ returnfalse; } } //获取当前日期function getDateStr(type){ var d =new Date(new Date().getTime()); var year=d.getFullYear(); var month=d.getMonth()+1; var date=d.getDate(); var hour=d.getHours(); var minute=d.getMinutes(); var second=d.getSeconds(); if(month<10){ month="0"+month; } if(date<10){ date="0"+date; } if("DateTime"==type){ return"["+year+"-"+month+"-"+date+""+hour+":"+minute+":"+second+"] "; } return year+""+month+""+date; } </script></head><body><!--仅支持IE浏览器--><input type="button" onclick="logInfo(‘printerror‘,‘this is printerror recorder‘)" value="JS创建文件"/></body></html>
参考文章:https://msdn.microsoft.com/zh-cn/library/314cz14s
原文:http://www.cnblogs.com/chuyuan/p/4829447.html
内容总结
以上是互联网集市为您收集整理的IE浏览器下用JS创建文件全部内容,希望文章能够帮你解决IE浏览器下用JS创建文件所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。