【已解决】window.open实现图片预览而非下载

简介: window.open实现图片预览而非下载

一、问题

  • 多个 图片 url (用逗号分隔开)
  • 图片 url 打开预览而非直接下载

二、解决

let imgs = row.url.split(',').filter(i => !!i)
let a = window.open('')
imgs.forEach((item, index) => {
  // window.open(item, `img${index}`) // 尝试失败
  a.document.write(`<!DOCTYPE html><html><body ><img src='${item}'/></body></html>`)
})

实际项目中最终使用了图片预览的组件。。。

三、其他尝试

在了解到 Content-Disposition 属性的限制之前,有尝试过使用 window.open() 的第二个参数 name 不同而同时启动多个下载。。。


参考资料:

相关文章
|
10月前
electron设置window系统托盘
electron设置window系统托盘
132 0
|
JavaScript
Element-ui中 使用图片查看器(el-image-viewer) 预览图片
Element-ui中 使用图片查看器(el-image-viewer) 预览图片
1463 0
Element-ui中 使用图片查看器(el-image-viewer) 预览图片
|
4天前
|
JavaScript 前端开发 UED
使用window.open打开新窗口的参数设置
使用window.open打开新窗口的参数设置
|
15天前
|
前端开发 JavaScript UED
window.open()用法详解
window.open()用法详解
|
2月前
|
JavaScript
window.open的使用
window.open的使用
69 0
|
2月前
使用PDF.js预览文件老是报错Message: file origin does not match viewer‘s_otherError @ app.js:1140怎么办??
使用PDF.js预览文件老是报错Message: file origin does not match viewer‘s_otherError @ app.js:1140怎么办??
|
小程序 前端开发 UED
wx-open-launch-weapp 样式问题
wx-open-launch-weapp 样式问题
767 0
wx-open-launch-weapp 样式问题
|
Web App开发 JavaScript 前端开发

热门文章

最新文章