![]()
<script type="text/javascript">
if (window.File)
{ window.alert("File APIが実装されてます。"); }
else
{ window.alert("本ブラウザではFile APIが使えません");
}
</script>
|
<!DOCTYPE html>
<html>
<head>
<title>File-API Write Sample</title>
<meta charset="UTF-8">
<script>
function doDownload() {
var textdata = document.getElementById( "dspArea" ).value;
var filename = document.getElementById( "filename" ).value;
var blob = new Blob( [ textdata ], { "type" : "text/plain" } );
if ( window.navigator.msSaveBlob ) { // IE
window.navigator.msSaveBlob( blob, filename );
} else {
var a = document.createElement( "a" );
a.download = filename;
a.href = window.URL.createObjectURL( blob );
var div = document.getElementById( "controls" );
div.appendChild( a );
a.click();
div.removeChild( a );
}
}
</script>
</head>
<body>
<div id="controls">
<input type="text" id="filename" value="output.txt" />
<input type="button" value="download" onclick="doDownload()" />
</div>
<div id="contents">
<textarea id="dspArea" rows="10" cols="30"></textarea>
</div>
</body>
</html>
|
![]()
<!DOCTYPE html>
<html>
<head>
<title>File-API Write Sample</title>
<meta charset="UTF-8">
</head>
<body>
<script>
let blob = new Blob(['あいうえお\n', '01234567\n', 'abcdefg\n', 'ABDEFG\n'],{type:"text/plan"});
let link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = 'test.txt';
link.click();
</script>
</body>
</html>
|
<html>
<head>
<meta charset=utf-8>
<title>Text Put</title>
<script>
function txt_put(file, ary)
{ var blob = new Blob([ary],{type:"text/plan"});
var link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = file;
link.click();
}
</script>
</head>
<body>
<script>
var dat= new Array("0123456789\n", "ABCDEFG\n", "abcdefg\n", "text_put Test Data\n");
window.onload=(txt_put("test.txt", dat));
</script>
</body>
</html>
|
![]()