gpt4 book ai didi

javascript - 使用 pdf.js 防止 idm 自动下载 PDF

转载 作者:行者123 更新时间:2023-12-02 23:54:00 31 4
gpt4 key购买 nike

我正在使用PDF.Js嵌入 PDF 文件进行预览,我从 viewer.js 中删除了下载和打开文件的脚本,但是当我测试页面和 PDF 文件尝试显示时,Internet Download Manager 下载它并中止预览..搜索后我发现使用 object 而不是 iframe 可以解决问题,但它不起作用,pdf 查看器显示为白色,我该怎么办防止自动下载?或者使用另一种方式(插件)来显示PDF文件内容。

<iframe 
class="pdf"
webkitallowfullscreen=""
mozallowfullscreen=""
allowfullscreen=""
frameborder="no"
width="'.$width.'"
height="'.$height.'"
src="'.$baseurl.'/assets/pdf/web/viewer.html?file='.urlencode($pdf_url).'"
data-src="'.$pdf_url.'">
'.$pdf_url.'
</iframe>

enter image description here

最佳答案

这与开发问题无关,这是与用户特定环境相关的问题。

问题:

使用 IDM ,任何以媒体扩展名结尾的 URL(例如 *.JPG 、 *.PNG 、 *.MP4 、 *.WMV 、 *.PDF ..etc )都会自动下载,但是另一方面,如果用户没有安装IDM,该文件将立即在浏览器窗口中查看。

可能的解决方案:

  1. 从 IDM 中删除 PDF 扩展处理程序,以防止自动下载,我认为该图像很好地解释了这一点。

IDM prevent file types from being handled

  • 修改 PDF 链接的响应 header 以强制浏览器在其 View 中查看 pdf,请考虑每个浏览器可能以不同方式处理响应,有关此方法的更多详细信息可以找到 here
  • 最后说明:

    As a developer you shouldnt handle each user specific environment , we suppose that when user installs a specific app to handle generic files , then it is his/her role to handle that application , and not the developer role , cause if you follow this algorithm you jump inside infinite loop handling different users specific setup.

    关于javascript - 使用 pdf.js 防止 idm 自动下载 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29954361/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com