| 192 | return copyButton |
| 193 | } |
| 194 | function downloadFile(url, filename) { |
| 195 | var xhr = new XMLHttpRequest() |
| 196 | xhr.open('GET', url, true) |
| 197 | xhr.responseType = 'blob' |
| 198 | xhr.onload = function () { |
| 199 | if (xhr.status === 200) { |
| 200 | var blob = xhr.response |
| 201 | var objectUrl = window.URL.createObjectURL(blob) |
| 202 | var a = document.createElement('a') |
| 203 | a.href = objectUrl |
| 204 | a.download = filename // 设置下载文件名 |
| 205 | document.body.appendChild(a) |
| 206 | a.click() |
| 207 | window.URL.revokeObjectURL(objectUrl) // 清理 object URL |
| 208 | document.body.removeChild(a) // 清理 DOM |
| 209 | } |
| 210 | } |
| 211 | xhr.send() |
| 212 | } |
| 213 | function getFilenameFromUrl(url) { |
| 214 | if (typeof url !== 'string' || url.trim() === '') { |
| 215 | logMessage('getFilenameFromUrl', 'URL无效,默认文件名download', false) |