[英]How to prevent auto download of doc/docx/pdf file on iframe src
I want to build a blurred preview of the document.我想构建文档的模糊预览。 The document is uploaded to the same domain.
文档上传到同一个域。 The document can be doc/docx/pdf .
该文档可以是doc/docx/pdf 。 I tried so many workarounds with
iframe
, embed
, object
.我用
iframe
、 embed
、 object
尝试了很多变通方法。
<iframe src="URL" title="Embedded Document" style="width:100%; height:500px; border: none;"></iframe>
<iframe src="URL#toolbar=0" title="Embedded Document" style="width:100%; height:500px; border: none;"></iframe>
<embed src="URL">
<object data="URL"></object>
But nothing achieve my requirement.但没有什么能达到我的要求。
TASK: I want to show a preview of the document on the web page which can not be downloadable.任务:我想在无法下载的网页上显示文档的预览。 Above workarounds, auto-downloads the doc/docx file when I refresh the web page.
上述解决方法,当我刷新网页时自动下载 doc/docx 文件。 I want a blurred preview of the document like here: https://essaybatch.com/how-would-you-convene-and-run-your-meetings-if-you-are-based-in-the-united-states/ and the file shouldn't be auto-downloaded.
我想要像这里这样的文档的模糊预览: https : //essaybatch.com/how-would-you-convene-and-run-your-meetings-if-you-are-based-in-the-united-states /并且不应自动下载该文件。
This requirement is strongly stated by the client, so I can't avoid the feature.客户强烈要求此要求,因此我无法避免该功能。 You're able to use HTML,CSS,JS,PHP.
您可以使用 HTML、CSS、JS、PHP。
Here's how I would implement it:这是我将如何实现它:
Use a PHP library to take a screenshot of the document and save it as an image.使用 PHP 库截取文档的屏幕截图并将其保存为图像。 In the iframe source, you should include that image and blur it using CSS.
在 iframe 源中,您应该包含该图像并使用 CSS 对其进行模糊处理。 Do not include the link to the actual
.doc
file because it is a security risk.不要包含指向实际
.doc
文件的链接,因为它存在安全风险。
Add JS listener to page for a cookie that contains a secret value.将 JS 侦听器添加到包含秘密值的 cookie 的页面。 When cookie is set to that value, page reloads and changes the iframe source to the file location for download.
当 cookie 设置为该值时,页面会重新加载并将 iframe 源更改为要下载的文件位置。
After payment is completed, return a callback with the secret value (token) that sets the cookie via PHP.支付完成后,通过PHP返回一个带有设置cookie的秘密值(令牌)的回调。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.