var a = document.createElement('a');
a.setAttribute('href', url);
a.setAttribute('download', url.split('/').pop()); //分割路径,取出最后一个元素
a.setAttribute('target', '_blank');
a.setAttribute('id', 'DownloadFile');// 防止反复添加
if(document.getElementById('DownloadFile')) {
document.body.removeChild(document.getElementById('DownloadFile'));
}
document.body.appendChild(a);
a.click();
网友评论