js 파일 흐름, txt 내 보 내기

10237 단어 파일 흐름
js 파일 흐름, txt 내 보 내기

var content = "file content!";
var data = new Blob([content],{type:"text/plain;charset=UTF-8"});
var downloadUrl = window.URL.createObjectURL(data);
var anchor = document.createElement("a");
anchor.href = downloadUrl;
anchor.download = "   .txt";
anchor.click();
window.URL.revokeObjectURL(data);

//    
var blob = new Blob([       ], { type: 'application/octet-stream' }),
fileName = 'filename' + path.substring(path.lastIndexOf("."), path.length);
////filename,        ,        mimetypes = array(
////    'doc'        => 'application/msword',
////    'bin'        => 'application/octet-stream',
////    'exe'        => 'application/octet-stream',
////    'so'        => 'application/octet-stream',
////    'dll'        => 'application/octet-stream',
////    'pdf'        => 'application/pdf',
////    'ai'        => 'application/postscript',
////    'xls'        => 'application/vnd.ms-excel',
////    'ppt'        => 'application/vnd.ms-powerpoint',
////    'dir'        => 'application/x-director',
////    'js'        => 'application/x-javascript',
////    'swf'        => 'application/x-shockwave-flash',
////    'xhtml'        => 'application/xhtml+xml',
////    'xht'        => 'application/xhtml+xml',
////    'zip'        => 'application/zip',
////    'mid'        => 'audio/midi',
////    'midi'        => 'audio/midi',
////    'mp3'        => 'audio/mpeg',
////    'rm'        => 'audio/x-pn-realaudio',
////    'rpm'        => 'audio/x-pn-realaudio-plugin',
////    'wav'        => 'audio/x-wav',
////    'bmp'        => 'image/bmp',
////    'gif'        => 'image/gif',
////    'jpeg'        => 'image/jpeg',
////    'jpg'        => 'image/jpeg',
////    'png'        => 'image/png',
////    'css'        => 'text/css',
////    'html'        => 'text/html',
////    'htm'        => 'text/html',
////    'txt'        => 'text/plain',
////    'xsl'        => 'text/xml',
////    'xml'        => 'text/xml',
////    'mpeg'        => 'video/mpeg',
////    'mpg'        => 'video/mpeg',
////    'avi'        => 'video/x-msvideo',
////    'movie'        => 'video/x-sgi-movie',
////);
downFile(blob, fileName);

//js     
    function downFile(blob, fileName) {
        if (window.navigator.msSaveOrOpenBlob) {
            navigator.msSaveBlob(blob, fileName);
        } else {
            var link = document.createElement('a');
            link.href = window.URL.createObjectURL(blob);
            link.download = fileName;
            link.click();
            window.URL.revokeObjectURL(link.href);
        }
    }

다음으로 이동:https://blog.csdn.net/lixiaoer757/article/details/80272281

좋은 웹페이지 즐겨찾기