Php 下载文件时,加载图标将持续显示
下载pdf文件时,加载图标会一直显示在页面中。下载文件时,似乎会触发Php 下载文件时,加载图标将持续显示,php,jquery,pdf,download,header,Php,Jquery,Pdf,Download,Header,下载pdf文件时,加载图标会一直显示在页面中。下载文件时,似乎会触发beforeunload功能(显示加载图标),尽管页面未卸载。我的代码会有什么错误 <html> <head> <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script> </head> <body> <script>
beforeunload
功能(显示加载图标),尽管页面未卸载。我的代码会有什么错误
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
</head>
<body>
<script>
$(window).on('beforeunload', function(event) {
$('#loading').show();
});
$(window).on('load', function(event) {
$('#loading').hide();
});
</script>
<div id="loading">Loading...</div>
<a href="t1.php?pdf=<?php echo 'Intro.pdf';?>"><button>download</button></a>
<?php
if(isset($_GET['pdf'])){
$bbpdf = $_GET['pdf'];
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false); // required for certain browsers
header("Content-Type: application/pdf");
header("Content-Disposition: attachment; filename=\"" . basename($bbpdf));
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($bbpdf));
ob_clean();
flush();
readfile($bbpdf);
}
?>
</body>
</html>
$(窗口).on('beforeunload',函数(事件){
$(“#加载”).show();
});
$(窗口).on('load',函数(事件){
$(“#加载”).hide();
});
加载。。。
这里的问题是,浏览器不知道请求的文件实际上是文件下载,而不是要显示的内联页面。那么解决方案是什么?很抱歉,我没有解决方案。您可能希望找到一种方法来检测单击的链接是否导致下载资源,如果是,则不显示加载元素。文件正在下载,并且加载图标仍在显示。您可能会在我的回答中发现一些有趣的内容