在Internet Explorer中强制下载音频文件

时间:2019-05-14 12:08:23

标签: javascript jquery

我正在整理此网站http://showtimesnow.com/bvofc/,并在Internet Explorer中对其进行了测试,发现下载按钮功能正在将音频文件下载为.htm文件。 以下是我的JavaScript下载功能代码。

function Download(fileURL, fileName) {
    // for non-IE
    if (!window.ActiveXObject) {
        var save = document.createElement('a');
        save.href = fileURL;
        save.target = '_blank';
        save.download = fileName || 'unknown';

    try{
        var evt = new MouseEvent('click', {
            'view': window,
            'bubbles': true,
            'cancelable': false
        });
        save.dispatchEvent(evt);
        (window.URL || window.webkitURL).revokeObjectURL(save.href);
    } catch(e){
        // for IE == 11
        if(!!navigator.userAgent.match(/Trident.*rv\:11\./)){
            save.click();
        }
    }
    }
    // for IE < 11
    else if ( !! window.ActiveXObject && document.execCommand){
        var _window = window.open(fileURL, '_blank');
        _window.document.close();
        _window.document.execCommand('SaveAs', true, fileName || fileURL)
        _window.close();
    }
}

我希望输出与URL中提供的文件相同。

0 个答案:

没有答案