IE瀏覽器下用JS建立檔案

來源:互聯網
上載者:User

標籤:

<!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)){                return true;    }else{                return false;        }}//檢查檔案是否存在,是true否falsefunction checkFileExists(fso,filePath){        if(fso.FileExists(filePath)){        return true;    }else{        return false;        }}//擷取當前日期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

 

IE瀏覽器下用JS建立檔案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.