admin管理员组

文章数量:1606474

js文件下载?简单啊,a标签的download属性,然后点击即下载。
http://www.w3school/tags/att_a_download.asp
官方也说了只有 Firefox 和 Chrome 支持 download 属性。
那我IE11怎么办,于是我开始了无尽的百度与尝试。


// 方法一:window.open没用,只是打开文件。
let output = '/static/download/aaa.txt'
let downloadFileName = 'testa'
if (window.navigator.msSaveBlob) {
    // for ie 10 and later
    try {
        let blobObject = new Blob([output])
        window.navigator.msSaveBlob(blobObject, downloadFileName)
    } catch (e) {
        console.log(e)
    }
} else {
    let file = 'data:text/plain;charset=utf-8,'
    let logFile = output
    let encoded = encodeURIComponent(logFile)
    file += encoded
    let a = document.createElement('a')
    a.href = file
    a.target =

本文标签: 火狐文档js