1.form表单
html
<form id="test" action="/download" method="get/post">
<input type="hidden" name="data" value="">
<button class="btn" type="submit">下载</button>
</form>
js
document.getElementById("sujia").value= ‘123’;
varform =document.getElementById('form');
form.submit();
2.iframe
html
<iframe name="download" class="download-iframe" style="display:none;"></iframe>
js
$('.download-iframe').on('load',function() {
consterrorMsg = $(this.contentWindow.document).text();
if(errorMsg){
window.setTimeout(function() {
dialog.error('下载文件失败,请联系管理员!');
},400);
}
});
window.open(`/download`,'download');
3. a标签
<a download="b" href="/download">下载</a>
js
var isSupportDownload = 'download' in document.createElement('a');
下载后文件重命名为b,由于兼容问题可以先尝试,是否支持