哪个做网站公司好,邢台信息港房产出租,织梦通用企业网站模板,济南市建设工程招标网官网使用 window.location.href 和 window.open 后都是打开图片#xff0c;原因是#xff0c;当浏览器发现是浏览器支持的文件类型#xff0c;例如 jpg、png、svg 等#xff0c;默认是浏览器打开。
解决
fetch createObjectURL fetch 转换为 blob 对象 createObjectURL() 静…使用 window.location.href 和 window.open 后都是打开图片原因是当浏览器发现是浏览器支持的文件类型例如 jpg、png、svg 等默认是浏览器打开。
解决
fetch createObjectURL fetch 转换为 blob 对象 createObjectURL() 静态方法创建一个用于表示参数中给出的对象的 URL 的字符串
function downloadImg(url) {fetch(url, {headers: new Headers({Origin: location.origin,}),mode: cors,}).then((res) {if (res.status 200) {// 生成 blob 对象return res.blob();}throw new Error(status: ${response.status}.);}).then((blob) {download(blob, image);});}function download(blob: Blob, filename?: string) {const a: any document.createElement(a);a.download filename;const blobUrl URL.createObjectURL(blob);a.href blobUrl;document.body.appendChild(a);a.click();a.remove();URL.revokeObjectURL(blobUrl);}