简体   繁体   English

使用iFrame自动下载

[英]Auto-Download Using iFrame

I am making available a file for users to download on my site. 我正在提供文件供用户下载到我的网站上。 What I want to achieve is auto-download functionality, so that whenever a user visits a download page, download dialog should automatically appear and if they click Run file should get executed. 我要实现的是自动下载功能,因此,每当用户访问下载页面时,下载对话框都将自动出现,并且如果他们单击运行文件,则应该执行该对话框。 The logic I am using is this - 我正在使用的逻辑是-

<iframe src='download_link' height='1' width='1' style='display:none;'>

I am placing this line at the end of the html code, and works fine, except when some system has Anti-Virus like for example Norton Internet Security . 我将这一行放在html代码的末尾,并且工作正常,除非某些系统具有防病毒功能(例如Norton Internet Security)

I want to know whether its even possible to overcome this problem, or is there any other secured way to provide the same functionality to users ? 我想知道是否有可能克服这个问题,或者是否有其他安全的方法可以为用户提供相同的功能?

To make such a download possible, you could use the following: 为了使这种下载成为可能,您可以使用以下方法:

<meta http-equiv="refresh" content="0;URL='download_link'">

As a meta-tag, this should be placed in the of your file. 作为元标记,应将其放置在文件的中。 However, you could make a js-function to edit the location after loading. 但是,您可以在加载后制作一个js函数来编辑位置。

location.href = 'download_link';

With this, the browser will load the file and download it, but will preserve the old document. 这样,浏览器将加载并下载文件,但会保留旧文档。 If the file will be something that can be opened in the browser (eg a pdf-document), you'll need to open it in an other tab via Javascript. 如果该文件是可以在浏览器中打开的文件(例如pdf文档),则需要通过Javascript在其他选项卡中打开它。

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

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