我正在尝试下载iOS上Blob格式的PDF。它可以在Desktop / Android上正常运行,但不能在iOS上的任何浏览器上正常运行。有谁对为什么这行不通有任何见识?
export function setBlobtoLink (url, fileName) {
const xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'blob';
xhr.setRequestHeader('Content-Type', 'application/pdf');
xhr.onload = function xhrOnload () {
if (this.status === 200) {
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(this.response);
} else {
const data = window.URL.createObjectURL(this.response);
const link = document.createElement('a');
document.body.appendChild(link);
link.style.display = 'none';
link.href = data;
link.download = fileName;
link.target = '_blank';
link.click();
window.URL.revokeObjectURL(data);
link.remove();
}
}
};
xhr.send();
}