简体   繁体   English

Javascript-预览失败时避免通过浏览器下载文件

[英]Javascript - avoid download file by browser when preview is failing

I am using quasar-framework with vue and I am binding an object propertie to embed a document in a iframe after the user clicks the link which redirects to the path of the file. 我在vue中使用类框架,并且在用户单击重定向到文件路径的链接后,将对象属性绑定到iframe中嵌入文档。 I don't want to fix the one that is not showing me the file I just want to solve the following: 我不想修复未显示文件的文件,我只想解决以下问题:

Is there any way to prevent the browser from downloading by default a selected file to be viewed embedded in an iframe when it can not be displayed? 有什么方法可以阻止浏览器默认情况下下载无法显示在iframe中的选定文件,以供查看。

<iframe id="content_iframe" v-bind:src="file.content_url" style="width:100%; background-color: gray" frameborder="0" scrolling="no"></iframe>

The file.content_url contains: "http://10.20.60.30:5010/files/1/content/" file.content_url包含: "http://10.20.60.30:5010/files/1/content/"

I need to control this because when I load the new route (then File.vue is loaded) the browser downloads the file with the name 'content' and I want to avoid this and that from that new route the user can download or not the file through a button (which works). 我需要对此进行控制,因为当我加载新路由(然后加载File.vue)时,浏览器会下载名称为“ content”的文件,并且我想避免这种情况,并且用户可以从该新路由中下载或不下载该文件。通过一个按钮(有效)文件。

You should use the tag object instead of iframe for embedding documents. 您应该使用标记object而不是iframe来嵌入文档。 If the browser can't render the document embedded inside object , it will not force the download and nothing will be displayed. 如果浏览器无法呈现嵌入object的文档,则不会强制下载,并且不会显示任何内容。

<object width="400" height="400" data="FILE_URL" type="FILE_CONTENT_TYPE">
    <embed src="FILE_URL" type="FILE_CONTENT_TYPE" />
</object>

Source: 资源:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM