HTML5 表單元件:client端客戶端電腦,儲存純文字檔案


 



 


(1).開啟檔案元件

<input id="file01" type="file" onchange="show02(this)"/>

(2).取得檔案參數

filename = thisfileinfo.files[0].name;
filesize= thisfileinfo.files[0].size;
filetype= thisfileinfo.files[0].type;
注意:可以複選

(3).讀取純文字檔的內容

function show02(fileinfo) {
file = fileinfo.files[0];
var fReader = new FileReader();
fReader.onload = function (event) {
document.getElementById('txt01').value = event.target.result;
};
fReader.readAsText(file);
}

(4).儲存純文字檔

function show04() {
var data = document.getElementById('txt01').value;
window.location.href = "data:application/x-download;charset=utf-8," + encodeURIComponent(data)}

 

(5).目前儲存文檔的瓶頸

W3C的html5 FileAPI, FileWriter都還在發展中,很多技術還沒開發完善。

因此,html5 FileWriter API幾乎沒有瀏覽器實做,因此Writer無法使用,不過目前可用兩種替代方式,來做文字檔的輸出: