internet-explorer - 即在 iframe 中显示 base 64 编码文件
问题描述
我有一个 base 64 字符串和文件 mime 类型和文件名。该文件可以是各种类型,例如图像、pdf、office 文件等。我的 html 中有一个 iframe 来显示 base 64 内容。它在 chrome 中运行良好,并显示 pdf、图像、文本文件和下载 docx(我也宁愿在 iframe 中显示)我使用的代码:
viewFile(cont, ftype, fname) {
let mime = mimeTypes.getType(fname);
var downloadLink = document.createElement('a');
downloadLink.href = typeof cont === 'string'
? this.createFileStreamForConverting(cont, mime, fname)
: window.URL.createObjectURL(cont);
if(mime == 'application/pdf')
{
const blobUrl = window.URL.createObjectURL(this.b64toBlob(cont, mime));
downloadLink.href = blobUrl;
}
downloadLink.style.display = 'none';
downloadLink.target = 'origFileViewFrame';
document.body.appendChild(downloadLink);
downloadLink.type = mime;
if(this.isDownloadType(ftype))
downloadLink.download = fname;
downloadLink.click();
}
我试图在 ie 上运行代码,但无法显示带有错误的项目:传递给系统调用的数据区域太小。所以我搜索并看到 ie 有一个问题,可以使用 msSaveBlob 解决
if (navigator && navigator.msSaveBlob) {
navigator.msSaveBlob(cont, fname);
}
但我不想下载文件。还有其他方法吗?另外,我希望文件显示在 iframe 中,而不是在空白窗口中。有什么事吗?
解决方案
推荐阅读
- vue.js - Vuex Action Handler Context Object 和 Payload ESLint 规则问题
- python-3.x - 在 Hello World 烧瓶应用程序中,Flask 找不到该应用程序
- ios - 自定义表格视图单元格上的附件详细信息按钮⇒内存泄漏
- django - NGINX 和 Gunicorn 的静态媒体故障
- python - 将多个 csv 文件导入 pandas 并连接到一个 DataFrame 中,其中所有 csv 中的第一列相同,并且没有数据标题只是文件名
- java - Firebase身份验证与电子邮件和密码额外字段重复 - Android - Java
- scala - Scala Spark中的年份函数返回错误的年份
- ruby-on-rails - Ruby on rails rails-devise-roles 示例应用程序
- prometheus - Grafana“节点导出器已满”仪表板在导入后不显示任何数据
- django - 优化 Django 中的数据库请求