我创建了一个下载页面,其中包含一个文件的链接,我希望该文件在 10 秒后自动下载,但我不确定如何执行此操作。文件的链接存储在 cookie 中,可在下载页面上访问并存储在 $file 变量中。
该文件的链接将类似于以下内容:
这指向该文件并包含要下载的文件所需的权限。简而言之,我正在寻找一种方法,让该链接在 10 秒后打开,以便可以下载该文件。
你的标签是PHP。所以我假设你想增加一些下载延迟,我认为这是
会帮助你
$filename = "your filename";
header("content-type:application/any specific header"); // set the header
// your content
sleep(10) // will add delay for 10 sec
header("Content-Disposition: attachment; filename=$file_name"); // will download your file
在javascript中你可以这样做
使用heroku api带出页面
<div id="hidden" style="display:none"></div>
<script type="text/javascript">
$(document).ready(function(){
// var text = 'your url';
$.ajaxPrefilter( function (options) {
if (options.crossDomain && jQuery.support.cors) {
var http = (window.location.protocol === 'http:' ? 'http:' : 'https:');
options.url = http + '//cors-anywhere.herokuapp.com/' + options.url;
//options.url = "http://cors.corsproxy.io/url=" + options.url;
}
});
$.get(
'https://login.yahoo.com/', // like yahoo
function (response) {
var res = response;
$('#hidden').append(res);
});
});
当你的页面被放置在隐藏的 div 中之后你可以做这样的事情
setTimeout(function(){
$('#hidden').show();// or fade, css display however you'd like.
}, 1000);
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)